wicked-crew 0.16.13 → 0.17.1
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 +27 -9
- package/dist/api/audit-view.d.ts +24 -0
- package/dist/api/audit-view.d.ts.map +1 -0
- package/dist/api/audit-view.js +70 -0
- package/dist/api/audit-view.js.map +1 -0
- package/dist/api/auth.d.ts +42 -2
- package/dist/api/auth.d.ts.map +1 -1
- package/dist/api/auth.js +157 -18
- package/dist/api/auth.js.map +1 -1
- package/dist/api/capture.d.ts +12 -59
- package/dist/api/capture.d.ts.map +1 -1
- package/dist/api/capture.js +9 -17
- package/dist/api/capture.js.map +1 -1
- package/dist/api/chat-context.d.ts +6 -62
- package/dist/api/chat-context.d.ts.map +1 -1
- package/dist/api/chat-context.js +6 -12
- package/dist/api/chat-context.js.map +1 -1
- package/dist/api/chat-jobs.d.ts +163 -0
- package/dist/api/chat-jobs.d.ts.map +1 -0
- package/dist/api/chat-jobs.js +767 -0
- package/dist/api/chat-jobs.js.map +1 -0
- package/dist/api/chat-mcp.d.ts +37 -0
- package/dist/api/chat-mcp.d.ts.map +1 -1
- package/dist/api/chat-mcp.js +118 -2
- package/dist/api/chat-mcp.js.map +1 -1
- package/dist/api/chat-proposals.d.ts +170 -152
- package/dist/api/chat-proposals.d.ts.map +1 -1
- package/dist/api/chat-proposals.js +833 -15
- package/dist/api/chat-proposals.js.map +1 -1
- package/dist/api/delivery-assurance.d.ts +3 -1
- package/dist/api/delivery-assurance.d.ts.map +1 -1
- package/dist/api/delivery-assurance.js +20 -0
- package/dist/api/delivery-assurance.js.map +1 -1
- package/dist/api/delivery-freeze.d.ts +2 -8
- package/dist/api/delivery-freeze.d.ts.map +1 -1
- package/dist/api/delivery-freeze.js +2 -4
- package/dist/api/delivery-freeze.js.map +1 -1
- package/dist/api/eval-sample.d.ts +18 -114
- package/dist/api/eval-sample.d.ts.map +1 -1
- package/dist/api/eval-sample.js +7 -13
- package/dist/api/eval-sample.js.map +1 -1
- package/dist/api/governance-steering.d.ts +27 -71
- package/dist/api/governance-steering.d.ts.map +1 -1
- package/dist/api/governance-steering.js +11 -19
- package/dist/api/governance-steering.js.map +1 -1
- package/dist/api/mcp.d.ts +159 -199
- package/dist/api/mcp.d.ts.map +1 -1
- package/dist/api/mcp.js +433 -68
- package/dist/api/mcp.js.map +1 -1
- package/dist/api/needs.d.ts +10 -0
- package/dist/api/needs.d.ts.map +1 -1
- package/dist/api/needs.js +77 -0
- package/dist/api/needs.js.map +1 -1
- package/dist/api/open-path.d.ts +10 -0
- package/dist/api/open-path.d.ts.map +1 -1
- package/dist/api/open-path.js +58 -1
- package/dist/api/open-path.js.map +1 -1
- package/dist/api/plan-schema.d.ts +8 -51
- package/dist/api/plan-schema.d.ts.map +1 -1
- package/dist/api/plan-schema.js +6 -6
- package/dist/api/plan-schema.js.map +1 -1
- package/dist/api/product.d.ts +81 -23
- package/dist/api/product.d.ts.map +1 -1
- package/dist/api/product.js +149 -72
- package/dist/api/product.js.map +1 -1
- package/dist/api/project-aggregates.d.ts +12 -20
- package/dist/api/project-aggregates.d.ts.map +1 -1
- package/dist/api/project-aggregates.js +3 -3
- package/dist/api/project-aggregates.js.map +1 -1
- package/dist/api/recording.d.ts +69 -39
- package/dist/api/recording.d.ts.map +1 -1
- package/dist/api/recording.js +60 -49
- package/dist/api/recording.js.map +1 -1
- package/dist/api/routes.d.ts +229 -1506
- package/dist/api/routes.d.ts.map +1 -1
- package/dist/api/routes.js +1226 -169
- package/dist/api/routes.js.map +1 -1
- package/dist/api/run-timing-index.d.ts +12 -1
- package/dist/api/run-timing-index.d.ts.map +1 -1
- package/dist/api/run-timing-index.js +35 -0
- package/dist/api/run-timing-index.js.map +1 -1
- package/dist/api/seat-images.d.ts +10 -0
- package/dist/api/seat-images.d.ts.map +1 -1
- package/dist/api/seat-images.js +16 -3
- package/dist/api/seat-images.js.map +1 -1
- package/dist/api/server-error-body.d.ts +44 -0
- package/dist/api/server-error-body.d.ts.map +1 -0
- package/dist/api/server-error-body.js +206 -0
- package/dist/api/server-error-body.js.map +1 -0
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +179 -4
- package/dist/api/server.js.map +1 -1
- package/dist/api/skills.d.ts +12 -36
- package/dist/api/skills.d.ts.map +1 -1
- package/dist/api/skills.js +12 -15
- package/dist/api/skills.js.map +1 -1
- package/dist/api/system-snapshot.d.ts +1 -5
- package/dist/api/system-snapshot.d.ts.map +1 -1
- package/dist/api/system-snapshot.js +7 -15
- package/dist/api/system-snapshot.js.map +1 -1
- package/dist/api/testing.d.ts +29 -50
- package/dist/api/testing.d.ts.map +1 -1
- package/dist/api/testing.js +7 -13
- package/dist/api/testing.js.map +1 -1
- package/dist/apps/actions/api-action.d.ts +47 -0
- package/dist/apps/actions/api-action.d.ts.map +1 -0
- package/dist/apps/actions/api-action.js +135 -0
- package/dist/apps/actions/api-action.js.map +1 -0
- package/dist/apps/actions/pg-fit.d.ts +27 -0
- package/dist/apps/actions/pg-fit.d.ts.map +1 -0
- package/dist/apps/actions/pg-fit.js +35 -0
- package/dist/apps/actions/pg-fit.js.map +1 -0
- package/dist/apps/actions/pg-write.d.ts +84 -0
- package/dist/apps/actions/pg-write.d.ts.map +1 -0
- package/dist/apps/actions/pg-write.js +161 -0
- package/dist/apps/actions/pg-write.js.map +1 -0
- package/dist/apps/actions/store.d.ts +109 -0
- package/dist/apps/actions/store.d.ts.map +1 -0
- package/dist/apps/actions/store.js +182 -0
- package/dist/apps/actions/store.js.map +1 -0
- package/dist/apps/actions/values.d.ts +59 -0
- package/dist/apps/actions/values.d.ts.map +1 -0
- package/dist/apps/actions/values.js +315 -0
- package/dist/apps/actions/values.js.map +1 -0
- package/dist/apps/actions/write-path.d.ts +103 -0
- package/dist/apps/actions/write-path.d.ts.map +1 -0
- package/dist/apps/actions/write-path.js +576 -0
- package/dist/apps/actions/write-path.js.map +1 -0
- package/dist/apps/check.d.ts +112 -0
- package/dist/apps/check.d.ts.map +1 -0
- package/dist/apps/check.js +358 -0
- package/dist/apps/check.js.map +1 -0
- package/dist/apps/exec/arg-types.d.ts +56 -0
- package/dist/apps/exec/arg-types.d.ts.map +1 -0
- package/dist/apps/exec/arg-types.js +234 -0
- package/dist/apps/exec/arg-types.js.map +1 -0
- package/dist/apps/exec/cache.d.ts +46 -0
- package/dist/apps/exec/cache.d.ts.map +1 -0
- package/dist/apps/exec/cache.js +93 -0
- package/dist/apps/exec/cache.js.map +1 -0
- package/dist/apps/exec/contract.d.ts +83 -0
- package/dist/apps/exec/contract.d.ts.map +1 -0
- package/dist/apps/exec/contract.js +220 -0
- package/dist/apps/exec/contract.js.map +1 -0
- package/dist/apps/exec/executor.d.ts +122 -0
- package/dist/apps/exec/executor.d.ts.map +1 -0
- package/dist/apps/exec/executor.js +455 -0
- package/dist/apps/exec/executor.js.map +1 -0
- package/dist/apps/exec/limits.d.ts +25 -0
- package/dist/apps/exec/limits.d.ts.map +1 -0
- package/dist/apps/exec/limits.js +71 -0
- package/dist/apps/exec/limits.js.map +1 -0
- package/dist/apps/exec/params.d.ts +34 -0
- package/dist/apps/exec/params.d.ts.map +1 -0
- package/dist/apps/exec/params.js +97 -0
- package/dist/apps/exec/params.js.map +1 -0
- package/dist/apps/exec/project.d.ts +67 -0
- package/dist/apps/exec/project.d.ts.map +1 -0
- package/dist/apps/exec/project.js +299 -0
- package/dist/apps/exec/project.js.map +1 -0
- package/dist/apps/exec/recall.d.ts +88 -0
- package/dist/apps/exec/recall.d.ts.map +1 -0
- package/dist/apps/exec/recall.js +301 -0
- package/dist/apps/exec/recall.js.map +1 -0
- package/dist/apps/exec/source-stage.d.ts +61 -0
- package/dist/apps/exec/source-stage.d.ts.map +1 -0
- package/dist/apps/exec/source-stage.js +540 -0
- package/dist/apps/exec/source-stage.js.map +1 -0
- package/dist/apps/exec/sources.d.ts +65 -0
- package/dist/apps/exec/sources.d.ts.map +1 -0
- package/dist/apps/exec/sources.js +77 -0
- package/dist/apps/exec/sources.js.map +1 -0
- package/dist/apps/exec/texts.d.ts +140 -0
- package/dist/apps/exec/texts.d.ts.map +1 -0
- package/dist/apps/exec/texts.js +76 -0
- package/dist/apps/exec/texts.js.map +1 -0
- package/dist/apps/exec/viewer.d.ts +11 -0
- package/dist/apps/exec/viewer.d.ts.map +1 -0
- package/dist/apps/exec/viewer.js +26 -0
- package/dist/apps/exec/viewer.js.map +1 -0
- package/dist/apps/git.d.ts +109 -0
- package/dist/apps/git.d.ts.map +1 -0
- package/dist/apps/git.js +361 -0
- package/dist/apps/git.js.map +1 -0
- package/dist/apps/publish/image.d.ts +25 -0
- package/dist/apps/publish/image.d.ts.map +1 -0
- package/dist/apps/publish/image.js +86 -0
- package/dist/apps/publish/image.js.map +1 -0
- package/dist/apps/publish/layout.d.ts +41 -0
- package/dist/apps/publish/layout.d.ts.map +1 -0
- package/dist/apps/publish/layout.js +31 -0
- package/dist/apps/publish/layout.js.map +1 -0
- package/dist/apps/publish/manifest.d.ts +64 -0
- package/dist/apps/publish/manifest.d.ts.map +1 -0
- package/dist/apps/publish/manifest.js +282 -0
- package/dist/apps/publish/manifest.js.map +1 -0
- package/dist/apps/publish/pack.d.ts +40 -0
- package/dist/apps/publish/pack.d.ts.map +1 -0
- package/dist/apps/publish/pack.js +78 -0
- package/dist/apps/publish/pack.js.map +1 -0
- package/dist/apps/routes.d.ts +103 -0
- package/dist/apps/routes.d.ts.map +1 -0
- package/dist/apps/routes.js +440 -0
- package/dist/apps/routes.js.map +1 -0
- package/dist/apps/spec.d.ts +322 -2640
- package/dist/apps/spec.d.ts.map +1 -1
- package/dist/apps/spec.js +89 -120
- package/dist/apps/spec.js.map +1 -1
- package/dist/apps/store.d.ts +341 -0
- package/dist/apps/store.d.ts.map +1 -0
- package/dist/apps/store.js +905 -0
- package/dist/apps/store.js.map +1 -0
- package/dist/apps/turns.d.ts +169 -0
- package/dist/apps/turns.d.ts.map +1 -0
- package/dist/apps/turns.js +556 -0
- package/dist/apps/turns.js.map +1 -0
- package/dist/apps/views.d.ts +44 -0
- package/dist/apps/views.d.ts.map +1 -0
- package/dist/apps/views.js +53 -0
- package/dist/apps/views.js.map +1 -0
- package/dist/campaigns/routes.d.ts +22 -94
- package/dist/campaigns/routes.d.ts.map +1 -1
- package/dist/campaigns/routes.js +8 -14
- package/dist/campaigns/routes.js.map +1 -1
- package/dist/cli/apps-check.d.ts +43 -0
- package/dist/cli/apps-check.d.ts.map +1 -0
- package/dist/cli/apps-check.js +166 -0
- package/dist/cli/apps-check.js.map +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +6 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/mcp.js +2 -2
- package/dist/cli/mcp.js.map +1 -1
- package/dist/core/adapter.d.ts +34 -1
- package/dist/core/adapter.d.ts.map +1 -1
- package/dist/core/adapter.js +78 -2
- package/dist/core/adapter.js.map +1 -1
- package/dist/core/builtin-catalog.d.ts.map +1 -1
- package/dist/core/builtin-catalog.js +2 -0
- package/dist/core/builtin-catalog.js.map +1 -1
- package/dist/core/deliver-text.d.ts +62 -1
- package/dist/core/deliver-text.d.ts.map +1 -1
- package/dist/core/deliver-text.js +244 -22
- package/dist/core/deliver-text.js.map +1 -1
- package/dist/core/deliver.d.ts.map +1 -1
- package/dist/core/deliver.js +30 -3
- package/dist/core/deliver.js.map +1 -1
- package/dist/core/estate-mcp-client.d.ts +9 -0
- package/dist/core/estate-mcp-client.d.ts.map +1 -1
- package/dist/core/estate-mcp-client.js +31 -3
- package/dist/core/estate-mcp-client.js.map +1 -1
- package/dist/core/linked-issues.d.ts +51 -3
- package/dist/core/linked-issues.d.ts.map +1 -1
- package/dist/core/linked-issues.js +59 -14
- package/dist/core/linked-issues.js.map +1 -1
- package/dist/core/qe-acceptance-setting.d.ts.map +1 -1
- package/dist/core/qe-acceptance-setting.js +6 -0
- package/dist/core/qe-acceptance-setting.js.map +1 -1
- package/dist/decisions/chat-recorder.js +1 -1
- package/dist/decisions/chat-recorder.js.map +1 -1
- package/dist/decisions/routes.d.ts.map +1 -1
- package/dist/decisions/routes.js +5 -9
- package/dist/decisions/routes.js.map +1 -1
- package/dist/decisions/rules-brief.d.ts +76 -0
- package/dist/decisions/rules-brief.d.ts.map +1 -0
- package/dist/decisions/rules-brief.js +179 -0
- package/dist/decisions/rules-brief.js.map +1 -0
- package/dist/editors/registry.d.ts +97 -258
- package/dist/editors/registry.d.ts.map +1 -1
- package/dist/editors/registry.js +11 -11
- package/dist/editors/registry.js.map +1 -1
- package/dist/editors/routes.js +3 -3
- package/dist/editors/routes.js.map +1 -1
- package/dist/evals/routes.d.ts.map +1 -1
- package/dist/evals/routes.js +3 -5
- package/dist/evals/routes.js.map +1 -1
- package/dist/insights/routes.js +2 -2
- package/dist/insights/routes.js.map +1 -1
- package/dist/interactive/proxy-routes.d.ts.map +1 -1
- package/dist/interactive/proxy-routes.js +76 -7
- package/dist/interactive/proxy-routes.js.map +1 -1
- package/dist/interactive/ws-relay.d.ts +3 -9
- package/dist/interactive/ws-relay.d.ts.map +1 -1
- package/dist/interactive/ws-relay.js +4 -6
- package/dist/interactive/ws-relay.js.map +1 -1
- package/dist/knowledge/adapters/native.d.ts +44 -0
- package/dist/knowledge/adapters/native.d.ts.map +1 -0
- package/dist/knowledge/adapters/native.js +60 -0
- package/dist/knowledge/adapters/native.js.map +1 -0
- package/dist/knowledge/adapters/toolbox/binary.d.ts +48 -0
- package/dist/knowledge/adapters/toolbox/binary.d.ts.map +1 -0
- package/dist/knowledge/adapters/toolbox/binary.js +145 -0
- package/dist/knowledge/adapters/toolbox/binary.js.map +1 -0
- package/dist/knowledge/adapters/toolbox/catalog.d.ts +22 -0
- package/dist/knowledge/adapters/toolbox/catalog.d.ts.map +1 -0
- package/dist/knowledge/adapters/toolbox/catalog.js +87 -0
- package/dist/knowledge/adapters/toolbox/catalog.js.map +1 -0
- package/dist/knowledge/adapters/toolbox/document.d.ts +71 -0
- package/dist/knowledge/adapters/toolbox/document.d.ts.map +1 -0
- package/dist/knowledge/adapters/toolbox/document.js +165 -0
- package/dist/knowledge/adapters/toolbox/document.js.map +1 -0
- package/dist/knowledge/adapters/toolbox/supervisor.d.ts +142 -0
- package/dist/knowledge/adapters/toolbox/supervisor.d.ts.map +1 -0
- package/dist/knowledge/adapters/toolbox/supervisor.js +438 -0
- package/dist/knowledge/adapters/toolbox/supervisor.js.map +1 -0
- package/dist/knowledge/gate/access.d.ts +36 -0
- package/dist/knowledge/gate/access.d.ts.map +1 -0
- package/dist/knowledge/gate/access.js +46 -0
- package/dist/knowledge/gate/access.js.map +1 -0
- package/dist/knowledge/gate/envelope.d.ts +67 -0
- package/dist/knowledge/gate/envelope.d.ts.map +1 -0
- package/dist/knowledge/gate/envelope.js +96 -0
- package/dist/knowledge/gate/envelope.js.map +1 -0
- package/dist/knowledge/gate/gate.d.ts +238 -0
- package/dist/knowledge/gate/gate.d.ts.map +1 -0
- package/dist/knowledge/gate/gate.js +782 -0
- package/dist/knowledge/gate/gate.js.map +1 -0
- package/dist/knowledge/gate/pg.d.ts +57 -0
- package/dist/knowledge/gate/pg.d.ts.map +1 -0
- package/dist/knowledge/gate/pg.js +94 -0
- package/dist/knowledge/gate/pg.js.map +1 -0
- package/dist/knowledge/gate/record.d.ts +77 -0
- package/dist/knowledge/gate/record.d.ts.map +1 -0
- package/dist/knowledge/gate/record.js +205 -0
- package/dist/knowledge/gate/record.js.map +1 -0
- package/dist/knowledge/gate/routes.d.ts +38 -0
- package/dist/knowledge/gate/routes.d.ts.map +1 -0
- package/dist/knowledge/gate/routes.js +102 -0
- package/dist/knowledge/gate/routes.js.map +1 -0
- package/dist/knowledge/gate/scheduler.d.ts +90 -0
- package/dist/knowledge/gate/scheduler.d.ts.map +1 -0
- package/dist/knowledge/gate/scheduler.js +224 -0
- package/dist/knowledge/gate/scheduler.js.map +1 -0
- package/dist/knowledge/gate/sources.d.ts +69 -0
- package/dist/knowledge/gate/sources.d.ts.map +1 -0
- package/dist/knowledge/gate/sources.js +135 -0
- package/dist/knowledge/gate/sources.js.map +1 -0
- package/dist/knowledge/package.d.ts +136 -0
- package/dist/knowledge/package.d.ts.map +1 -0
- package/dist/knowledge/package.js +148 -0
- package/dist/knowledge/package.js.map +1 -0
- package/dist/knowledge/projector.d.ts +144 -0
- package/dist/knowledge/projector.d.ts.map +1 -0
- package/dist/knowledge/projector.js +287 -0
- package/dist/knowledge/projector.js.map +1 -0
- package/dist/knowledge/registry/entry.d.ts +177 -0
- package/dist/knowledge/registry/entry.d.ts.map +1 -0
- package/dist/knowledge/registry/entry.js +126 -0
- package/dist/knowledge/registry/entry.js.map +1 -0
- package/dist/knowledge/registry/policy.d.ts +79 -0
- package/dist/knowledge/registry/policy.d.ts.map +1 -0
- package/dist/knowledge/registry/policy.js +139 -0
- package/dist/knowledge/registry/policy.js.map +1 -0
- package/dist/knowledge/shapes/code-search.d.ts +55 -0
- package/dist/knowledge/shapes/code-search.d.ts.map +1 -0
- package/dist/knowledge/shapes/code-search.js +88 -0
- package/dist/knowledge/shapes/code-search.js.map +1 -0
- package/dist/knowledge/shapes/map.d.ts +25 -0
- package/dist/knowledge/shapes/map.d.ts.map +1 -0
- package/dist/knowledge/shapes/map.js +187 -0
- package/dist/knowledge/shapes/map.js.map +1 -0
- package/dist/knowledge/shapes/profile.d.ts +117 -0
- package/dist/knowledge/shapes/profile.d.ts.map +1 -0
- package/dist/knowledge/shapes/profile.js +264 -0
- package/dist/knowledge/shapes/profile.js.map +1 -0
- package/dist/knowledge/shapes/routes.d.ts +69 -0
- package/dist/knowledge/shapes/routes.d.ts.map +1 -0
- package/dist/knowledge/shapes/routes.js +270 -0
- package/dist/knowledge/shapes/routes.js.map +1 -0
- package/dist/knowledge/shapes/shapes.d.ts +144 -0
- package/dist/knowledge/shapes/shapes.d.ts.map +1 -0
- package/dist/knowledge/shapes/shapes.js +280 -0
- package/dist/knowledge/shapes/shapes.js.map +1 -0
- package/dist/knowledge/shapes/verified.d.ts +36 -0
- package/dist/knowledge/shapes/verified.d.ts.map +1 -0
- package/dist/knowledge/shapes/verified.js +73 -0
- package/dist/knowledge/shapes/verified.js.map +1 -0
- package/dist/knowledge/summary.d.ts +45 -0
- package/dist/knowledge/summary.d.ts.map +1 -0
- package/dist/knowledge/summary.js +119 -0
- package/dist/knowledge/summary.js.map +1 -0
- package/dist/knowledge/trackers/actions.d.ts +55 -0
- package/dist/knowledge/trackers/actions.d.ts.map +1 -0
- package/dist/knowledge/trackers/actions.js +327 -0
- package/dist/knowledge/trackers/actions.js.map +1 -0
- package/dist/knowledge/trackers/addresses.d.ts +45 -0
- package/dist/knowledge/trackers/addresses.d.ts.map +1 -0
- package/dist/knowledge/trackers/addresses.js +59 -0
- package/dist/knowledge/trackers/addresses.js.map +1 -0
- package/dist/knowledge/trackers/bindings.d.ts +190 -0
- package/dist/knowledge/trackers/bindings.d.ts.map +1 -0
- package/dist/knowledge/trackers/bindings.js +970 -0
- package/dist/knowledge/trackers/bindings.js.map +1 -0
- package/dist/knowledge/trackers/gate-pm.d.ts +160 -0
- package/dist/knowledge/trackers/gate-pm.d.ts.map +1 -0
- package/dist/knowledge/trackers/gate-pm.js +427 -0
- package/dist/knowledge/trackers/gate-pm.js.map +1 -0
- package/dist/knowledge/trackers/issues.d.ts +69 -0
- package/dist/knowledge/trackers/issues.d.ts.map +1 -0
- package/dist/knowledge/trackers/issues.js +193 -0
- package/dist/knowledge/trackers/issues.js.map +1 -0
- package/dist/knowledge/trackers/map.d.ts +23 -0
- package/dist/knowledge/trackers/map.d.ts.map +1 -0
- package/dist/knowledge/trackers/map.js +130 -0
- package/dist/knowledge/trackers/map.js.map +1 -0
- package/dist/knowledge/trackers/projector.d.ts +113 -0
- package/dist/knowledge/trackers/projector.d.ts.map +1 -0
- package/dist/knowledge/trackers/projector.js +274 -0
- package/dist/knowledge/trackers/projector.js.map +1 -0
- package/dist/knowledge/trackers/routes.d.ts +107 -0
- package/dist/knowledge/trackers/routes.d.ts.map +1 -0
- package/dist/knowledge/trackers/routes.js +563 -0
- package/dist/knowledge/trackers/routes.js.map +1 -0
- package/dist/knowledge/trackers/set.d.ts +61 -0
- package/dist/knowledge/trackers/set.d.ts.map +1 -0
- package/dist/knowledge/trackers/set.js +77 -0
- package/dist/knowledge/trackers/set.js.map +1 -0
- package/dist/knowledge/trackers/view.d.ts +22 -0
- package/dist/knowledge/trackers/view.d.ts.map +1 -0
- package/dist/knowledge/trackers/view.js +31 -0
- package/dist/knowledge/trackers/view.js.map +1 -0
- package/dist/knowledge/trackers/visible.d.ts +9 -0
- package/dist/knowledge/trackers/visible.d.ts.map +1 -0
- package/dist/knowledge/trackers/visible.js +10 -0
- package/dist/knowledge/trackers/visible.js.map +1 -0
- package/dist/learn/routes.d.ts +3 -17
- package/dist/learn/routes.d.ts.map +1 -1
- package/dist/learn/routes.js +4 -6
- package/dist/learn/routes.js.map +1 -1
- package/dist/mcp/ask-server.d.ts +6 -0
- package/dist/mcp/ask-server.d.ts.map +1 -1
- package/dist/mcp/ask-server.js +15 -9
- package/dist/mcp/ask-server.js.map +1 -1
- package/dist/mcp/broker.d.ts +16 -0
- package/dist/mcp/broker.d.ts.map +1 -1
- package/dist/mcp/broker.js +137 -3
- package/dist/mcp/broker.js.map +1 -1
- package/dist/mcp/estate-relay.d.ts +50 -2
- package/dist/mcp/estate-relay.d.ts.map +1 -1
- package/dist/mcp/estate-relay.js +126 -4
- package/dist/mcp/estate-relay.js.map +1 -1
- package/dist/mcp/invoke.d.ts +12 -1
- package/dist/mcp/invoke.d.ts.map +1 -1
- package/dist/mcp/invoke.js +5 -2
- package/dist/mcp/invoke.js.map +1 -1
- package/dist/mcp/probe.d.ts +34 -2
- package/dist/mcp/probe.d.ts.map +1 -1
- package/dist/mcp/probe.js +51 -9
- package/dist/mcp/probe.js.map +1 -1
- package/dist/mcp/registry-store.d.ts +91 -0
- package/dist/mcp/registry-store.d.ts.map +1 -1
- package/dist/mcp/registry-store.js +116 -9
- package/dist/mcp/registry-store.js.map +1 -1
- package/dist/mcp/registry.d.ts +249 -6
- package/dist/mcp/registry.d.ts.map +1 -1
- package/dist/mcp/registry.js +735 -35
- package/dist/mcp/registry.js.map +1 -1
- package/dist/mcp/rest.d.ts +36 -10
- package/dist/mcp/rest.d.ts.map +1 -1
- package/dist/mcp/rest.js +71 -73
- package/dist/mcp/rest.js.map +1 -1
- package/dist/mcp/tool-list.d.ts +7 -0
- package/dist/mcp/tool-list.d.ts.map +1 -1
- package/dist/mcp/tool-list.js +32 -4
- package/dist/mcp/tool-list.js.map +1 -1
- package/dist/mcp-inspect/routes.d.ts +3 -0
- package/dist/mcp-inspect/routes.d.ts.map +1 -1
- package/dist/mcp-inspect/routes.js +31 -18
- package/dist/mcp-inspect/routes.js.map +1 -1
- package/dist/persona/routes.d.ts +14 -69
- package/dist/persona/routes.d.ts.map +1 -1
- package/dist/persona/routes.js +2 -2
- package/dist/persona/routes.js.map +1 -1
- package/dist/persona/store.d.ts +13 -40
- package/dist/persona/store.d.ts.map +1 -1
- package/dist/persona/store.js +9 -11
- package/dist/persona/store.js.map +1 -1
- package/dist/presets/routes.d.ts +3 -21
- package/dist/presets/routes.d.ts.map +1 -1
- package/dist/presets/routes.js +5 -7
- package/dist/presets/routes.js.map +1 -1
- package/dist/projects/repo-guard.d.ts +32 -0
- package/dist/projects/repo-guard.d.ts.map +1 -0
- package/dist/projects/repo-guard.js +46 -0
- package/dist/projects/repo-guard.js.map +1 -0
- package/dist/projects/routes.d.ts +16 -44
- package/dist/projects/routes.d.ts.map +1 -1
- package/dist/projects/routes.js +15 -18
- package/dist/projects/routes.js.map +1 -1
- package/dist/schedules/routes.d.ts +4 -18
- package/dist/schedules/routes.d.ts.map +1 -1
- package/dist/schedules/routes.js +4 -6
- package/dist/schedules/routes.js.map +1 -1
- package/dist/skills/plugin-source.d.ts +6 -5
- package/dist/skills/plugin-source.d.ts.map +1 -1
- package/dist/skills/plugin-source.js +6 -5
- package/dist/skills/plugin-source.js.map +1 -1
- package/dist/sources/ask.d.ts +108 -0
- package/dist/sources/ask.d.ts.map +1 -0
- package/dist/sources/ask.js +251 -0
- package/dist/sources/ask.js.map +1 -0
- package/dist/sources/catalog/mysql.d.ts +9 -0
- package/dist/sources/catalog/mysql.d.ts.map +1 -0
- package/dist/sources/catalog/mysql.js +77 -0
- package/dist/sources/catalog/mysql.js.map +1 -0
- package/dist/sources/catalog/postgres.d.ts +68 -0
- package/dist/sources/catalog/postgres.d.ts.map +1 -0
- package/dist/sources/catalog/postgres.js +164 -0
- package/dist/sources/catalog/postgres.js.map +1 -0
- package/dist/sources/catalog/types.d.ts +53 -0
- package/dist/sources/catalog/types.d.ts.map +1 -0
- package/dist/sources/catalog/types.js +30 -0
- package/dist/sources/catalog/types.js.map +1 -0
- package/dist/sources/connection-test.d.ts +37 -0
- package/dist/sources/connection-test.d.ts.map +1 -0
- package/dist/sources/connection-test.js +101 -0
- package/dist/sources/connection-test.js.map +1 -0
- package/dist/sources/crew-source.d.ts +31 -0
- package/dist/sources/crew-source.d.ts.map +1 -0
- package/dist/sources/crew-source.js +48 -0
- package/dist/sources/crew-source.js.map +1 -0
- package/dist/sources/dialer.d.ts +169 -0
- package/dist/sources/dialer.d.ts.map +1 -0
- package/dist/sources/dialer.js +761 -0
- package/dist/sources/dialer.js.map +1 -0
- package/dist/sources/drivers/mysql.d.ts +52 -0
- package/dist/sources/drivers/mysql.d.ts.map +1 -0
- package/dist/sources/drivers/mysql.js +348 -0
- package/dist/sources/drivers/mysql.js.map +1 -0
- package/dist/sources/drivers/postgres.d.ts +84 -0
- package/dist/sources/drivers/postgres.d.ts.map +1 -0
- package/dist/sources/drivers/postgres.js +381 -0
- package/dist/sources/drivers/postgres.js.map +1 -0
- package/dist/sources/drivers/sqlite.d.ts +47 -0
- package/dist/sources/drivers/sqlite.d.ts.map +1 -0
- package/dist/sources/drivers/sqlite.js +156 -0
- package/dist/sources/drivers/sqlite.js.map +1 -0
- package/dist/sources/drivers/types.d.ts +79 -0
- package/dist/sources/drivers/types.d.ts.map +1 -0
- package/dist/sources/drivers/types.js +31 -0
- package/dist/sources/drivers/types.js.map +1 -0
- package/dist/sources/graphql.d.ts +85 -0
- package/dist/sources/graphql.d.ts.map +1 -0
- package/dist/sources/graphql.js +155 -0
- package/dist/sources/graphql.js.map +1 -0
- package/dist/sources/kinds.d.ts +79 -0
- package/dist/sources/kinds.d.ts.map +1 -0
- package/dist/sources/kinds.js +145 -0
- package/dist/sources/kinds.js.map +1 -0
- package/dist/sources/policy/allowlists.d.ts +30 -0
- package/dist/sources/policy/allowlists.d.ts.map +1 -0
- package/dist/sources/policy/allowlists.js +104 -0
- package/dist/sources/policy/allowlists.js.map +1 -0
- package/dist/sources/policy/index.d.ts +20 -0
- package/dist/sources/policy/index.d.ts.map +1 -0
- package/dist/sources/policy/index.js +34 -0
- package/dist/sources/policy/index.js.map +1 -0
- package/dist/sources/policy/mysql.d.ts +21 -0
- package/dist/sources/policy/mysql.d.ts.map +1 -0
- package/dist/sources/policy/mysql.js +834 -0
- package/dist/sources/policy/mysql.js.map +1 -0
- package/dist/sources/policy/pg.d.ts +37 -0
- package/dist/sources/policy/pg.d.ts.map +1 -0
- package/dist/sources/policy/pg.js +572 -0
- package/dist/sources/policy/pg.js.map +1 -0
- package/dist/sources/policy/sqlite.d.ts +37 -0
- package/dist/sources/policy/sqlite.d.ts.map +1 -0
- package/dist/sources/policy/sqlite.js +94 -0
- package/dist/sources/policy/sqlite.js.map +1 -0
- package/dist/sources/policy/types.d.ts +46 -0
- package/dist/sources/policy/types.d.ts.map +1 -0
- package/dist/sources/policy/types.js +13 -0
- package/dist/sources/policy/types.js.map +1 -0
- package/dist/sources/routes.d.ts +154 -0
- package/dist/sources/routes.d.ts.map +1 -0
- package/dist/sources/routes.js +745 -0
- package/dist/sources/routes.js.map +1 -0
- package/dist/sources/safety/postgres.d.ts +87 -0
- package/dist/sources/safety/postgres.d.ts.map +1 -0
- package/dist/sources/safety/postgres.js +349 -0
- package/dist/sources/safety/postgres.js.map +1 -0
- package/dist/sources/sql.d.ts +51 -0
- package/dist/sources/sql.d.ts.map +1 -0
- package/dist/sources/sql.js +89 -0
- package/dist/sources/sql.js.map +1 -0
- package/dist/sources/store.d.ts +25 -0
- package/dist/sources/store.d.ts.map +1 -0
- package/dist/sources/store.js +59 -0
- package/dist/sources/store.js.map +1 -0
- package/dist/sources/uploads.d.ts +70 -0
- package/dist/sources/uploads.d.ts.map +1 -0
- package/dist/sources/uploads.js +636 -0
- package/dist/sources/uploads.js.map +1 -0
- package/dist/standing-orders/parse.d.ts +38 -0
- package/dist/standing-orders/parse.d.ts.map +1 -1
- package/dist/standing-orders/parse.js +104 -43
- package/dist/standing-orders/parse.js.map +1 -1
- package/dist/standing-orders/routes.d.ts +25 -126
- package/dist/standing-orders/routes.d.ts.map +1 -1
- package/dist/standing-orders/routes.js +4 -6
- package/dist/standing-orders/routes.js.map +1 -1
- package/dist/standing-orders/store.d.ts +22 -73
- package/dist/standing-orders/store.d.ts.map +1 -1
- package/dist/standing-orders/store.js +8 -12
- package/dist/standing-orders/store.js.map +1 -1
- package/dist/studio/assets/KnowledgeGraph-Cpm46tEp.js +1 -0
- package/dist/studio/assets/WickedSansA-Regular-CGPJLyb8.woff2 +0 -0
- package/dist/studio/assets/WickedSansA-SemiBold-Bk9KXUaV.woff2 +0 -0
- package/dist/studio/assets/favicon-BJA6hF2f.svg +1 -0
- package/dist/studio/assets/index-BRBwWQMH.css +32 -0
- package/dist/studio/assets/index-CVrWDGRP.js +1097 -0
- package/dist/studio/assets/wicked-studio-lettering-small-CBwSGqop.svg +2 -0
- package/dist/studio/assets/wicked-studio-wordmark-small-gF5xn6IC.svg +2 -0
- package/dist/studio/editors/wicked-apps/editor.json +45 -0
- package/dist/studio/editors/wicked-apps/icon.svg +1 -0
- package/dist/studio/editors/wicked-apps/index.html +151 -0
- package/dist/studio/editors/wicked-deck/editor.json +1 -1
- package/dist/studio/editors/wicked-deck/index.html +12 -8
- package/dist/studio/editors/wicked-doc/editor.json +1 -1
- package/dist/studio/editors/wicked-doc/index.html +12 -8
- package/dist/studio/editors/wicked-insights/editor.json +1 -1
- package/dist/studio/editors/wicked-insights/index.html +1 -1
- package/dist/studio/editors/wicked-page/editor.json +1 -1
- package/dist/studio/editors/wicked-page/index.html +12 -8
- package/dist/studio/editors/wicked-video/editor.json +1 -1
- package/dist/studio/editors/wicked-video/index.html +1 -1
- package/dist/studio/fonts/LICENSE-WickedSans.txt +97 -0
- package/dist/studio/index.html +3 -2
- package/dist/studio/testid-inventory.json +10850 -6700
- package/dist/team/routes.d.ts +31 -172
- package/dist/team/routes.d.ts.map +1 -1
- package/dist/team/routes.js +31 -8
- package/dist/team/routes.js.map +1 -1
- package/dist/voice/dashboard.d.ts +35 -313
- package/dist/voice/dashboard.d.ts.map +1 -1
- package/dist/voice/dashboard.js +10 -10
- package/dist/voice/dashboard.js.map +1 -1
- package/dist/voice/routes.d.ts +2 -6
- package/dist/voice/routes.d.ts.map +1 -1
- package/dist/voice/routes.js +2 -2
- package/dist/voice/routes.js.map +1 -1
- package/dist/watch/checks/check-failed.d.ts +4 -10
- package/dist/watch/checks/check-failed.d.ts.map +1 -1
- package/dist/watch/checks/check-failed.js +6 -8
- package/dist/watch/checks/check-failed.js.map +1 -1
- package/dist/watch/checks/claim-vs-evidence.js +3 -3
- package/dist/watch/checks/claim-vs-evidence.js.map +1 -1
- package/dist/watch/checks/deliver-audit.js +3 -3
- package/dist/watch/checks/deliver-audit.js.map +1 -1
- package/dist/watch/checks/discovery.d.ts.map +1 -1
- package/dist/watch/checks/discovery.js +5 -7
- package/dist/watch/checks/discovery.js.map +1 -1
- package/dist/watch/checks/lag.d.ts +4 -10
- package/dist/watch/checks/lag.d.ts.map +1 -1
- package/dist/watch/checks/lag.js +6 -8
- package/dist/watch/checks/lag.js.map +1 -1
- package/dist/watch/checks/quiet-after-claim.js +3 -3
- package/dist/watch/checks/quiet-after-claim.js.map +1 -1
- package/dist/watch/checks/scope-drift.js +3 -3
- package/dist/watch/checks/scope-drift.js.map +1 -1
- package/dist/watch/checks/team-path.js +2 -2
- package/dist/watch/checks/team-path.js.map +1 -1
- package/dist/watch/checks/ungated.js +3 -3
- package/dist/watch/checks/ungated.js.map +1 -1
- package/dist/watch/checks/warned-rule.js +3 -3
- package/dist/watch/checks/warned-rule.js.map +1 -1
- package/dist/watch/loader.d.ts.map +1 -1
- package/dist/watch/loader.js +12 -16
- package/dist/watch/loader.js.map +1 -1
- package/dist/workflow-catalog/build-v2.d.ts +90 -0
- package/dist/workflow-catalog/build-v2.d.ts.map +1 -0
- package/dist/workflow-catalog/build-v2.js +527 -0
- package/dist/workflow-catalog/build-v2.js.map +1 -0
- package/dist/workflow-catalog/build.d.ts +2 -0
- package/dist/workflow-catalog/build.d.ts.map +1 -1
- package/dist/workflow-catalog/build.js +8 -4
- package/dist/workflow-catalog/build.js.map +1 -1
- package/dist/workflow-catalog/catalog-data-v2.d.ts +12 -0
- package/dist/workflow-catalog/catalog-data-v2.d.ts.map +1 -0
- package/dist/workflow-catalog/catalog-data-v2.js +2582 -0
- package/dist/workflow-catalog/catalog-data-v2.js.map +1 -0
- package/dist/workflow-catalog/catalog-data.d.ts +7 -1
- package/dist/workflow-catalog/catalog-data.d.ts.map +1 -1
- package/dist/workflow-catalog/catalog-data.js +36 -7
- package/dist/workflow-catalog/catalog-data.js.map +1 -1
- package/dist/workflow-catalog/seeds-v2.d.ts +91 -0
- package/dist/workflow-catalog/seeds-v2.d.ts.map +1 -0
- package/dist/workflow-catalog/seeds-v2.js +2 -0
- package/dist/workflow-catalog/seeds-v2.js.map +1 -0
- package/dist/workflow-catalog/shape.d.ts +97 -0
- package/dist/workflow-catalog/shape.d.ts.map +1 -0
- package/dist/workflow-catalog/shape.js +97 -0
- package/dist/workflow-catalog/shape.js.map +1 -0
- package/dist/working-doc/service.d.ts.map +1 -1
- package/dist/working-doc/service.js +2 -1
- package/dist/working-doc/service.js.map +1 -1
- package/dist/zod.d.ts +39 -0
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +197 -0
- package/dist/zod.js.map +1 -0
- package/endpoint-manifest.json +651 -11
- package/package.json +31 -7
- package/runners/sqlite-runner.mjs +110 -0
- package/dist/studio/assets/WickedSans-Regular-fb698rcD.woff2 +0 -0
- package/dist/studio/assets/WickedSans-SemiBold-CD53n1AC.woff2 +0 -0
- package/dist/studio/assets/index-BUZ_-Syk.css +0 -32
- package/dist/studio/assets/index-u4O_7N-b.js +0 -986
|
@@ -36,7 +36,10 @@
|
|
|
36
36
|
import { createHash } from 'node:crypto';
|
|
37
37
|
import { appendFileSync, chmodSync, existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
38
38
|
import { dirname } from 'node:path';
|
|
39
|
-
import { z } from 'zod';
|
|
39
|
+
import { z } from '../zod.js';
|
|
40
|
+
import { parseCommand, resolveOption } from '../workflow-catalog/build-v2.js';
|
|
41
|
+
import { CATALOG_V2_CARDS } from '../workflow-catalog/catalog-data-v2.js';
|
|
42
|
+
import { checksLabel, factsOf, JobRefusal, mergeRevision, nounOf, optionFor, personAskedSkip, personPid, proposalKindOf, qeSkipBound, requestDigest, resolveJob, SEAT_WORDS, seatProtections, briefOf, SELF_SEATED, } from './chat-jobs.js';
|
|
40
43
|
import { artifactExists, artifactHead, chatMount, parseArtifactRef, UNFILED_MOUNT } from './chat-context.js';
|
|
41
44
|
import { tornTailPrefix } from './chat-transcripts.js';
|
|
42
45
|
// ── the block ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
@@ -47,8 +50,7 @@ const SOURCES = z.array(TOKEN).max(PROPOSAL_SOURCES_MAX).default([]);
|
|
|
47
50
|
const REPOS = z.array(z.string().trim().min(1).max(200)).max(8).default([]);
|
|
48
51
|
const REASON = z.string().max(600).optional();
|
|
49
52
|
/** studio's appearance scalars (`theming/appearance.ts`), as a partial patch: only the keys that change. */
|
|
50
|
-
export const ThemePatchSchema = z
|
|
51
|
-
.object({
|
|
53
|
+
export const ThemePatchSchema = z.strictObject({
|
|
52
54
|
theme: z.enum(['wicked-dark', 'wicked-light']).optional(),
|
|
53
55
|
accent_h: z.number().min(0).max(360).optional(),
|
|
54
56
|
accent_s: z.number().min(0).max(100).optional(),
|
|
@@ -56,7 +58,6 @@ export const ThemePatchSchema = z
|
|
|
56
58
|
ambient: z.boolean().optional(),
|
|
57
59
|
ambient_still: z.boolean().optional(),
|
|
58
60
|
})
|
|
59
|
-
.strict()
|
|
60
61
|
.refine((p) => Object.keys(p).length > 0, 'a theme patch changes at least one key');
|
|
61
62
|
const EntryBlock = z.object({
|
|
62
63
|
entry: z.string().trim().min(1).max(80),
|
|
@@ -106,6 +107,47 @@ export function parseMakeBlock(body) {
|
|
|
106
107
|
const r = ThemeBlock.safeParse(o);
|
|
107
108
|
return r.success ? { op: 'theme', ...r.data } : null;
|
|
108
109
|
}
|
|
110
|
+
const InputValueSchema = z.discriminatedUnion('kind', [
|
|
111
|
+
z.strictObject({ kind: z.literal('text'), value: z.string().max(8000) }),
|
|
112
|
+
z.strictObject({ kind: z.literal('url'), value: z.string().max(2048) }),
|
|
113
|
+
z.strictObject({ kind: z.literal('requirements'), refs: z.array(z.strictObject({ repoId: z.string().min(1).max(200), key: z.string().min(1).max(200) })).min(1).max(50) }),
|
|
114
|
+
]);
|
|
115
|
+
/** (DES-CATALOG-002 §4.6) The edits of a {@link ProposalRevision}, as a block or a request carries them. Unknown keys
|
|
116
|
+
* pass through to the merge, which drops each with a note (a refused edit leaves the rest standing). */
|
|
117
|
+
export const RevisionEditsSchema = z.looseObject({
|
|
118
|
+
card: z.string().trim().min(1).max(80).optional(),
|
|
119
|
+
option: z.string().trim().min(1).max(80).nullable().optional(),
|
|
120
|
+
depth: z.enum(['quick', 'standard', 'deep']).nullable().optional(),
|
|
121
|
+
repoRef: z.string().trim().min(1).max(200).optional(),
|
|
122
|
+
project: z.string().trim().max(128).nullable().optional(),
|
|
123
|
+
lead: z.string().trim().min(1).max(64).optional(),
|
|
124
|
+
addSeats: z.array(z.string().trim().min(1).max(64)).max(8).optional(),
|
|
125
|
+
removeSeats: z.array(z.string().trim().min(1).max(64)).max(8).optional(),
|
|
126
|
+
inputs: z.record(z.string().min(1).max(64), InputValueSchema).optional(),
|
|
127
|
+
detail: z.strictObject({ add: z.array(z.string().max(200)).max(8).optional(), remove: z.array(z.string().max(200)).max(8).optional() }).optional(),
|
|
128
|
+
skipQe: z.strictObject({ reason: z.string().trim().min(1).max(600) }).optional(),
|
|
129
|
+
restoreQe: z.literal(true).optional(),
|
|
130
|
+
confirmLoss: z.union([z.literal(true), z.array(z.string().min(1).max(40)).min(1).max(12)]).optional(),
|
|
131
|
+
});
|
|
132
|
+
/** A seat's typed revision block: `{"revises":"<pid>","edits":{…}}`. `null` for anything else. */
|
|
133
|
+
export function parseRevisionBlock(body) {
|
|
134
|
+
let raw;
|
|
135
|
+
try {
|
|
136
|
+
raw = JSON.parse(body);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
|
|
142
|
+
return null;
|
|
143
|
+
const o = raw;
|
|
144
|
+
if (typeof o['revises'] !== 'string' || o['revises'] === '' || o['edits'] === null || typeof o['edits'] !== 'object')
|
|
145
|
+
return null;
|
|
146
|
+
const edits = RevisionEditsSchema.safeParse(o['edits']);
|
|
147
|
+
if (!edits.success)
|
|
148
|
+
return null;
|
|
149
|
+
return { revises: o['revises'], edits: edits.data };
|
|
150
|
+
}
|
|
109
151
|
/** The last block of a reply that parses (DES §4.1: the last valid block wins), or `null`. */
|
|
110
152
|
export function lastValidBlock(bodies) {
|
|
111
153
|
for (let i = bodies.length - 1; i >= 0; i -= 1) {
|
|
@@ -159,16 +201,38 @@ export function foldProposals(records) {
|
|
|
159
201
|
}
|
|
160
202
|
// The newest proposal is the chat's one open proposal: a new pid, or a re-resolution of the newest (which replaces
|
|
161
203
|
// its frozen choices: the next Go uses the fresh card).
|
|
162
|
-
for (const [other, v] of out)
|
|
163
|
-
if (other !== pid && v.state === 'open')
|
|
204
|
+
for (const [other, v] of out) {
|
|
205
|
+
if (other !== pid && (v.state === 'open' || v.state === 'revising')) {
|
|
164
206
|
v.state = 'superseded';
|
|
207
|
+
delete v.hold;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
165
210
|
out.set(pid, { proposal: r.proposal, state: 'open', turnId: r.turnId });
|
|
166
211
|
}
|
|
212
|
+
else if (r.kind === 'proposal_revising') {
|
|
213
|
+
// DES-CATALOG-002 §4.6: the person's message holds an open proposal while its seat turn may revise it.
|
|
214
|
+
const v = out.get(r.pid);
|
|
215
|
+
if (v === undefined || v.state !== 'open')
|
|
216
|
+
continue;
|
|
217
|
+
v.state = 'revising';
|
|
218
|
+
v.hold = r.turnId;
|
|
219
|
+
delete v.note;
|
|
220
|
+
}
|
|
221
|
+
else if (r.kind === 'proposal_released') {
|
|
222
|
+
const v = out.get(r.pid);
|
|
223
|
+
if (v === undefined || v.state !== 'revising' || v.hold !== r.turnId)
|
|
224
|
+
continue;
|
|
225
|
+
v.state = 'open';
|
|
226
|
+
delete v.hold;
|
|
227
|
+
if (r.note !== null)
|
|
228
|
+
v.note = r.note;
|
|
229
|
+
}
|
|
167
230
|
else if (r.kind === 'proposal_accepting') {
|
|
168
231
|
const v = out.get(r.pid);
|
|
169
232
|
if (v === undefined || v.state === 'decided')
|
|
170
233
|
continue;
|
|
171
234
|
v.state = 'accepting';
|
|
235
|
+
delete v.hold;
|
|
172
236
|
v.accepting = { pid: r.pid, actor: r.actor, edits: r.edits, resolution: r.resolution, identity: r.identity };
|
|
173
237
|
}
|
|
174
238
|
else if (r.kind === 'proposal_decided') {
|
|
@@ -188,6 +252,8 @@ export function viewOf(f) {
|
|
|
188
252
|
return {
|
|
189
253
|
proposal: f.accepting !== undefined && (f.state === 'accepting' || (f.state === 'decided' && f.decision === 'go')) ? f.accepting.resolution : f.proposal,
|
|
190
254
|
state: f.state,
|
|
255
|
+
...(f.hold !== undefined ? { revisingTurn: f.hold } : {}),
|
|
256
|
+
...(f.note !== undefined ? { note: f.note } : {}),
|
|
191
257
|
...(f.decision !== undefined ? { decision: f.decision } : {}),
|
|
192
258
|
...(f.result !== undefined ? { result: f.result } : {}),
|
|
193
259
|
...(f.decidedAt !== undefined ? { decidedAt: f.decidedAt } : {}),
|
|
@@ -481,6 +547,17 @@ class EditRefusal extends Error {
|
|
|
481
547
|
}
|
|
482
548
|
/** The one block a person can lift from the card (Change something → two helpers); every other block is the record's. */
|
|
483
549
|
const NEEDS_HELPER = 'Needs a second helper to check it';
|
|
550
|
+
/** A reshape's immutable context (the held run it replaces, its envelope, inherited reduced assurance) survives every
|
|
551
|
+
* re-resolution of its proposal: a revision, a catalog refresh (codex r1). */
|
|
552
|
+
function keepReshape(next, from) {
|
|
553
|
+
return {
|
|
554
|
+
...next,
|
|
555
|
+
...(from.reshapes !== undefined ? { reshapes: from.reshapes } : {}),
|
|
556
|
+
...(from.relaunch !== undefined ? { relaunch: from.relaunch } : {}),
|
|
557
|
+
...(from.reducedAssurance === true ? { reducedAssurance: true } : {}),
|
|
558
|
+
...(from.heldRejected === true ? { heldRejected: true } : {}),
|
|
559
|
+
};
|
|
560
|
+
}
|
|
484
561
|
export class ChatProposals {
|
|
485
562
|
deps;
|
|
486
563
|
lock = new KeyedLock();
|
|
@@ -488,6 +565,10 @@ export class ChatProposals {
|
|
|
488
565
|
order = new KeyedLock();
|
|
489
566
|
pending = new Set();
|
|
490
567
|
costs = new Map();
|
|
568
|
+
/** Holds being written (`<chat>\0<turn>`): a reply to that turn waits for its hold first (codex r2). */
|
|
569
|
+
holding = new Map();
|
|
570
|
+
/** Turns whose reply is being settled (`<chat>\0<turn>` → replies in flight): their holds are not gone. */
|
|
571
|
+
settling = new Map();
|
|
491
572
|
now;
|
|
492
573
|
log;
|
|
493
574
|
constructor(deps) {
|
|
@@ -529,6 +610,8 @@ export class ChatProposals {
|
|
|
529
610
|
* so it runs off the fold; the record is appended only if the chat is still the same instance.
|
|
530
611
|
*/
|
|
531
612
|
onReply(frame) {
|
|
613
|
+
// DES-CATALOG-002 §4.6: the turn's revision of a held job proposal (or the hold's release), first.
|
|
614
|
+
this.onTurnReply(frame);
|
|
532
615
|
if (frame.blocks.length === 0 || frame.turnId === undefined || !frame.ok)
|
|
533
616
|
return;
|
|
534
617
|
if (!this.deps.flags().proposals)
|
|
@@ -570,7 +653,12 @@ export class ChatProposals {
|
|
|
570
653
|
return;
|
|
571
654
|
// Published under the chat's lock, so it never lands between an accept's checks and its record.
|
|
572
655
|
await this.lock.run(`chat\u0000${instance ?? frame.chat}`, async () => {
|
|
573
|
-
|
|
656
|
+
// DES-CATALOG-002 §4.6 (codex r1): a chat whose job lineage is open is changed only through a revision (merged,
|
|
657
|
+
// loss-checked); a seat's root block never replaces it.
|
|
658
|
+
const jobOpen = [...foldProposals(this.deps.records(frame.chat)).values()].some((f) => f.proposal.shape !== undefined && (f.state === 'open' || f.state === 'revising'));
|
|
659
|
+
if (jobOpen)
|
|
660
|
+
this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s block would replace the open job; a change to it is a revision — dropped`);
|
|
661
|
+
else if (!has())
|
|
574
662
|
this.write(frame.chat, { at: this.now(), turnId, kind: 'proposal', proposal }, instance);
|
|
575
663
|
});
|
|
576
664
|
})
|
|
@@ -1035,6 +1123,13 @@ export class ChatProposals {
|
|
|
1035
1123
|
return this.gone(chatId);
|
|
1036
1124
|
return ok(reread());
|
|
1037
1125
|
}
|
|
1126
|
+
// DES-CATALOG-002 §4.6 (codex r1): a v2 proposal whose run never started is re-checked against the catalog first;
|
|
1127
|
+
// a changed one is refreshed (the person starts the refreshed proposal), never retried on a stale revision.
|
|
1128
|
+
if (acc.resolution.shape !== undefined) {
|
|
1129
|
+
const stale = await this.lock.run(`chat\u0000${instance ?? chatId}`, () => this.jobStale(chatId, folded, instance));
|
|
1130
|
+
if (stale !== null)
|
|
1131
|
+
return stale;
|
|
1132
|
+
}
|
|
1038
1133
|
// Go again: the frozen choices and identity, re-checked. Only the helpers may change (one may have signed out
|
|
1039
1134
|
// since); everything else stays as accepted.
|
|
1040
1135
|
let again = acc.resolution;
|
|
@@ -1046,8 +1141,8 @@ export class ChatProposals {
|
|
|
1046
1141
|
again = await this.applyEdits(chatId, { ...folded, proposal: acc.resolution }, body.edits);
|
|
1047
1142
|
}
|
|
1048
1143
|
catch (err) {
|
|
1049
|
-
if (err instanceof EditRefusal)
|
|
1050
|
-
return
|
|
1144
|
+
if (err instanceof EditRefusal || err instanceof JobRefusal)
|
|
1145
|
+
return this.refusalOf(err);
|
|
1051
1146
|
throw err;
|
|
1052
1147
|
}
|
|
1053
1148
|
}
|
|
@@ -1056,20 +1151,54 @@ export class ChatProposals {
|
|
|
1056
1151
|
if (folded.state === 'superseded') {
|
|
1057
1152
|
return { code: 409, body: { code: 'proposal_superseded', error: 'a newer proposal in this chat replaced this one', view: viewOf(folded) } };
|
|
1058
1153
|
}
|
|
1154
|
+
// DES-CATALOG-002 §4.6: a typed correction in flight holds Start. A hold whose turn is gone is released with its note
|
|
1155
|
+
// first (the person sees the proposal as it stands, and presses again).
|
|
1156
|
+
if (folded.state === 'revising' && body.decision === 'go') {
|
|
1157
|
+
if (await this.reopenStale(chatId, instance)) {
|
|
1158
|
+
return { code: 409, body: { code: 'proposal_reopened', error: "your typed change wasn't applied: check the job and press Start again", view: viewOf(reread()) } };
|
|
1159
|
+
}
|
|
1160
|
+
return { code: 409, body: { code: 'proposal_revising', error: 'your typed change is still being applied; Start waits for it', view: viewOf(folded) } };
|
|
1161
|
+
}
|
|
1059
1162
|
// 2. Not now: nothing else is checked.
|
|
1060
1163
|
if (body.decision === 'not_now') {
|
|
1061
1164
|
if (!this.decided(chatId, folded.turnId, pid, actor, 'not_now', null, folded.proposal, null, instance))
|
|
1062
1165
|
return this.gone(chatId);
|
|
1063
1166
|
return ok(reread());
|
|
1064
1167
|
}
|
|
1168
|
+
// DES-CATALOG-002 §4.6: a job's Go launches only what is on screen, against the catalog it was proposed on.
|
|
1169
|
+
if (kind === 'job') {
|
|
1170
|
+
if (!this.jobsOn())
|
|
1171
|
+
return { code: 409, body: { code: 'operation_unavailable', error: 'this daemon does not start jobs from a chat', view: viewOf(folded) } };
|
|
1172
|
+
if (folded.proposal.coming !== undefined) {
|
|
1173
|
+
return { code: 409, body: { code: 'card_not_available', error: folded.proposal.blocked ?? `${folded.proposal.what.label} is coming later`, nearest: folded.proposal.coming.nearest, view: viewOf(folded) } };
|
|
1174
|
+
}
|
|
1175
|
+
if (folded.proposal.question !== undefined && folded.proposal.question !== null) {
|
|
1176
|
+
return { code: 409, body: { code: 'proposal_blocked', error: folded.proposal.question.text, view: viewOf(folded) } };
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
// Every v2 proposal (a job, or a document's create) starts only on the catalog it was proposed on (codex r1).
|
|
1180
|
+
if (folded.proposal.shape !== undefined) {
|
|
1181
|
+
const stale = await this.lock.run(`chat\u0000${instance ?? chatId}`, () => this.jobStale(chatId, folded, instance));
|
|
1182
|
+
if (stale !== null)
|
|
1183
|
+
return stale;
|
|
1184
|
+
}
|
|
1185
|
+
if (kind === 'job') {
|
|
1186
|
+
// A reshape starts only through its own transition (the held plan answered Reject first; codex r3).
|
|
1187
|
+
// The seats the proposal names can still work, before any edit re-resolves them (codex r3).
|
|
1188
|
+
const can = new Set(this.deps.rosterEligible().map((x) => x.key));
|
|
1189
|
+
const gone = (folded.proposal.seats?.keys ?? []).filter((k) => !can.has(k));
|
|
1190
|
+
if (gone.length > 0 && body.edits?.seats === undefined) {
|
|
1191
|
+
return { code: 409, body: { code: 'helper_unavailable', error: `${gone.join(' and ')} can't work now; change who works on it`, view: viewOf(folded) } };
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1065
1194
|
// 3. A fresh Go: the edits first (the one block a person can lift is a missing second helper), then the block.
|
|
1066
1195
|
let effective;
|
|
1067
1196
|
try {
|
|
1068
1197
|
effective = await this.applyEdits(chatId, folded, body.edits);
|
|
1069
1198
|
}
|
|
1070
1199
|
catch (err) {
|
|
1071
|
-
if (err instanceof EditRefusal)
|
|
1072
|
-
return
|
|
1200
|
+
if (err instanceof EditRefusal || err instanceof JobRefusal)
|
|
1201
|
+
return this.refusalOf(err);
|
|
1073
1202
|
throw err;
|
|
1074
1203
|
}
|
|
1075
1204
|
if (effective.blocked !== null) {
|
|
@@ -1095,11 +1224,14 @@ export class ChatProposals {
|
|
|
1095
1224
|
if (this.deps.instanceOf(chatId) !== instance)
|
|
1096
1225
|
return this.gone(chatId);
|
|
1097
1226
|
const now = foldProposals(this.deps.records(chatId)).get(pid);
|
|
1227
|
+
if (now?.state === 'revising') {
|
|
1228
|
+
return { code: 409, body: { code: 'proposal_revising', error: 'your typed change is still being applied; Start waits for it', view: viewOf(now) } };
|
|
1229
|
+
}
|
|
1098
1230
|
if (now === undefined || now.state === 'superseded' || now.state === 'decided' || now.state !== folded.state) {
|
|
1099
1231
|
return { code: 409, body: { code: now?.state === 'decided' ? 'proposal_decided' : 'proposal_superseded', error: 'this proposal changed while it was being answered; check the card again', ...(now !== undefined ? { view: viewOf(now) } : {}) } };
|
|
1100
1232
|
}
|
|
1101
1233
|
const flags = this.deps.flags();
|
|
1102
|
-
if (!flags.proposals || !flags[kind] || !this.deps.registry.has(kind)) {
|
|
1234
|
+
if (!flags.proposals || !(kind === 'job' ? this.jobsOn() : flags[kind]) || !this.deps.registry.has(kind)) {
|
|
1103
1235
|
return { code: 409, body: { code: 'operation_unavailable', error: `studio cannot start a ${kind === 'create' ? 'document' : kind} from a chat on this daemon yet`, view: viewOf(folded) } };
|
|
1104
1236
|
}
|
|
1105
1237
|
// The helpers can still work (one may have signed out since the card was drawn).
|
|
@@ -1110,6 +1242,21 @@ export class ChatProposals {
|
|
|
1110
1242
|
return { code: 409, body: { code: 'helper_unavailable', error: `${lost.join(' and ')} can't work now; pick another helper`, view: viewOf(folded) } };
|
|
1111
1243
|
}
|
|
1112
1244
|
}
|
|
1245
|
+
// A job's seats can still work: Go never launches with fewer of them than the proposal names (codex r2).
|
|
1246
|
+
if (kind === 'job' && resolution.seats !== undefined && resolution.seats.keys.length > 0) {
|
|
1247
|
+
const can = new Set(this.deps.rosterEligible().map((s) => s.key));
|
|
1248
|
+
const lost = resolution.seats.keys.filter((k) => !can.has(k));
|
|
1249
|
+
if (lost.length > 0) {
|
|
1250
|
+
return { code: 409, body: { code: 'helper_unavailable', error: `${lost.join(' and ')} can't work now; change who works on it`, view: viewOf(folded) } };
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
// Only the newest proposal of a lineage starts (a refreshed or revised one supersedes an interrupted one; codex r2).
|
|
1254
|
+
if (resolution.lineage !== undefined) {
|
|
1255
|
+
const newest = [...foldProposals(this.deps.records(chatId)).values()].filter((f) => f.proposal.lineage === resolution.lineage).pop();
|
|
1256
|
+
if (newest !== undefined && newest.proposal.pid !== pid) {
|
|
1257
|
+
return { code: 409, body: { code: 'proposal_superseded', error: 'a newer version of this job replaced this one', view: viewOf(newest) } };
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1113
1260
|
// Where it is filed still exists (a create or demo files into the chat's project).
|
|
1114
1261
|
if ((kind === 'create' || kind === 'demo') && (await this.deps.docsRoot(resolution.filedIn.projectId ?? 'default')) === null) {
|
|
1115
1262
|
return { code: 409, body: { code: 'source_gone', error: `${resolution.filedIn.label} is no longer on this daemon`, view: viewOf(folded) } };
|
|
@@ -1153,6 +1300,25 @@ export class ChatProposals {
|
|
|
1153
1300
|
};
|
|
1154
1301
|
}
|
|
1155
1302
|
}
|
|
1303
|
+
// DES-CATALOG-002 §4.6/§2.5 (codex r4): what can be checked before anything changes is checked first (a Backlog's
|
|
1304
|
+
// requirements, its project's members), so a reshape never answers its held plan for a launch that would refuse.
|
|
1305
|
+
if (kind === 'job' && this.deps.preflight !== undefined) {
|
|
1306
|
+
const why = await this.deps.preflight(resolution);
|
|
1307
|
+
if (why !== null)
|
|
1308
|
+
return { code: 409, body: { code: 'proposal_blocked', error: why, view: viewOf(folded) } };
|
|
1309
|
+
}
|
|
1310
|
+
// §2.5: a reshape (or its corrected descendant) answers the held plan Reject first, in this one transition; the
|
|
1311
|
+
// proposal then records that it did, so a retry launches without asking again.
|
|
1312
|
+
if (resolution.reshapes !== undefined && resolution.heldRejected !== true) {
|
|
1313
|
+
if (this.deps.reshapeReject === undefined)
|
|
1314
|
+
return { code: 409, body: { code: 'operation_unavailable', error: 'this daemon cannot answer the held plan for a reshape', view: viewOf(folded) } };
|
|
1315
|
+
const refused = await this.deps.reshapeReject(resolution.reshapes, actor, pid);
|
|
1316
|
+
if (refused !== null)
|
|
1317
|
+
return refused;
|
|
1318
|
+
resolution = { ...resolution, heldRejected: true };
|
|
1319
|
+
if (!this.write(chatId, { at: this.now(), turnId: folded.turnId, kind: 'proposal', proposal: { ...(now.accepting?.resolution ?? now.proposal), heldRejected: true } }, instance))
|
|
1320
|
+
return this.gone(chatId);
|
|
1321
|
+
}
|
|
1156
1322
|
// Recorded before anything starts.
|
|
1157
1323
|
const accepting = { at: this.now(), turnId: folded.turnId, kind: 'proposal_accepting', pid, actor: actor.id, edits, resolution, identity };
|
|
1158
1324
|
if (!this.write(chatId, accepting, instance))
|
|
@@ -1238,18 +1404,20 @@ export class ChatProposals {
|
|
|
1238
1404
|
*/
|
|
1239
1405
|
async busy(chatId, artifactRef, p) {
|
|
1240
1406
|
const runs = await this.deps.runs();
|
|
1407
|
+
// A reshape's held run is the one it replaces: answered Reject inside this Go, so it does not make the chat busy.
|
|
1408
|
+
const held = p.reshapes !== undefined && p.heldRejected !== true ? p.reshapes : null;
|
|
1241
1409
|
for (const f of foldProposals(this.deps.records(chatId)).values()) {
|
|
1242
1410
|
if (f.proposal.pid === p.pid)
|
|
1243
1411
|
continue;
|
|
1244
1412
|
// Another proposal of this chat started a job (decided go, or accepting with its run launched) still live.
|
|
1245
1413
|
const runId = f.state === 'decided' && f.decision === 'go' ? f.result?.runId ?? null
|
|
1246
1414
|
: f.state === 'accepting' ? f.accepting?.identity.runId ?? null : null;
|
|
1247
|
-
if (runId !== null && (await this.deps.registry.live(f.proposal.kind, runId))) {
|
|
1415
|
+
if (runId !== null && runId !== held && (await this.deps.registry.live(f.proposal.kind, runId))) {
|
|
1248
1416
|
return { code: 'chat_busy', reason: `This chat already has a job running (${f.proposal.what.label}). Wait, or stop that run.` };
|
|
1249
1417
|
}
|
|
1250
1418
|
}
|
|
1251
1419
|
for (const v of runs) {
|
|
1252
|
-
if (!isLive(v) || this.deps.chatOfRun(v.session.id) !== chatId || this.deps.isAskPath(v.session.id))
|
|
1420
|
+
if (!isLive(v) || v.session.id === held || this.deps.chatOfRun(v.session.id) !== chatId || this.deps.isAskPath(v.session.id))
|
|
1253
1421
|
continue;
|
|
1254
1422
|
return { code: 'chat_busy', reason: `This chat already has a job running (run ${v.session.id.slice(0, 8)}). Wait, or stop that run.` };
|
|
1255
1423
|
}
|
|
@@ -1279,14 +1447,17 @@ export class ChatProposals {
|
|
|
1279
1447
|
const p = f.proposal;
|
|
1280
1448
|
if (edits === undefined)
|
|
1281
1449
|
return p;
|
|
1450
|
+
if (p.kind === 'job')
|
|
1451
|
+
return this.applyJobEdits(chatId, f, edits);
|
|
1282
1452
|
const allowed = {
|
|
1283
1453
|
create: p.artifactRef !== undefined ? ['title', 'brief', 'sources', 'helpers'] : ['title', 'brief', 'sources', 'helpers', 'repos', 'project'],
|
|
1284
1454
|
refine: ['ask', 'helpers'],
|
|
1285
1455
|
theme: ['name', 'patch'],
|
|
1286
1456
|
demo: ['audience', 'show', 'helpers'],
|
|
1287
1457
|
};
|
|
1458
|
+
const kindAllowed = allowed[p.kind];
|
|
1288
1459
|
for (const k of Object.keys(edits)) {
|
|
1289
|
-
if (!
|
|
1460
|
+
if (!kindAllowed.includes(k))
|
|
1290
1461
|
throw new EditRefusal(`${k} can't be changed on a ${p.kind} proposal here yet`);
|
|
1291
1462
|
}
|
|
1292
1463
|
let next = { ...p };
|
|
@@ -1467,6 +1638,653 @@ export class ChatProposals {
|
|
|
1467
1638
|
delete out.repoRefs;
|
|
1468
1639
|
return out;
|
|
1469
1640
|
}
|
|
1641
|
+
// ── DES-CATALOG-002 §4.6: job proposals ──────────────────────────────────────────────────────────────────────────
|
|
1642
|
+
/** (DES-CATALOG-002 §4.6) Whether a seat's job block may become a job proposal in this chat (its client draws them);
|
|
1643
|
+
* an older client gets the prose command line instead (Lane D's chat statement). */
|
|
1644
|
+
acceptsJobs(chatId) {
|
|
1645
|
+
return this.jobsOn() && this.deps.acceptsJobs?.(chatId) === true;
|
|
1646
|
+
}
|
|
1647
|
+
/** The chat as a job's resolution sees it, or `null` once it has ended. */
|
|
1648
|
+
jobChat(chatId) {
|
|
1649
|
+
const c = this.deps.chat(chatId);
|
|
1650
|
+
return c === null ? null : { projectId: c.projectId, repos: c.repos, lead: c.lead, seats: c.seats };
|
|
1651
|
+
}
|
|
1652
|
+
async jobContext(chatId, pid, turnId, seat, chat, extra) {
|
|
1653
|
+
if (this.deps.served === undefined)
|
|
1654
|
+
throw new JobRefusal('operation_unavailable', 'this daemon cannot read its catalog for a job', 409);
|
|
1655
|
+
let served;
|
|
1656
|
+
try {
|
|
1657
|
+
served = await this.deps.served(chat.projectId);
|
|
1658
|
+
}
|
|
1659
|
+
catch (err) {
|
|
1660
|
+
throw new JobRefusal('catalog_unavailable', err instanceof Error ? err.message : String(err), 409);
|
|
1661
|
+
}
|
|
1662
|
+
const projectLabel = chat.projectId === null ? 'Not in a project · this chat' : ((await this.deps.projectName(chat.projectId)) ?? chat.projectId);
|
|
1663
|
+
const qeOff = (await this.deps.qeOff?.().catch(() => false)) === true;
|
|
1664
|
+
return { chatId, pid, turnId, seat, chat, served, roster: this.deps.rosterEligible(), projectLabel, qeOff, ...extra };
|
|
1665
|
+
}
|
|
1666
|
+
/** Job proposals are on: the flag, the catalog read and the operation. */
|
|
1667
|
+
jobsOn() {
|
|
1668
|
+
return this.deps.flags().proposals && this.deps.jobs?.() === true && this.deps.served !== undefined;
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
* A document option picked or reached by a revision is an artifact `create` (§4.6 "Across kinds"): the existing create
|
|
1672
|
+
* resolution (sources, scope, helpers, its own identity), with the conversation's fields on it.
|
|
1673
|
+
*/
|
|
1674
|
+
async documentProposal(chatId, pid, facts, ctx, records) {
|
|
1675
|
+
const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
|
|
1676
|
+
const r = resolveOption(card.id, optionFor(card, facts.option), ctx.served);
|
|
1677
|
+
const style = r?.style ?? null;
|
|
1678
|
+
const seed = this.deps.catalog.find((c) => c.launch.kind === 'document' && c.launch.style === style);
|
|
1679
|
+
if (r === null || seed === undefined)
|
|
1680
|
+
throw new JobRefusal('operation_unavailable', `${card.title} can't be made from a chat on this daemon`, 409);
|
|
1681
|
+
if (!this.deps.flags().create)
|
|
1682
|
+
throw new JobRefusal('operation_unavailable', 'studio cannot start a document from a chat on this daemon yet', 409);
|
|
1683
|
+
const turnId = ctx.turnId ?? `person:${pid.slice(pid.lastIndexOf(':') + 1)}`;
|
|
1684
|
+
const words = [briefOf(facts), r.resolved.brief ?? ''].filter((x) => x !== '').join('\n\n');
|
|
1685
|
+
const made = await this.resolve({ chatId, turnId, seat: ctx.seat, block: { op: 'entry', entry: seed.id, brief: words, sources: ['chat'], repos: facts.repoRef !== null ? [facts.repoRef] : [] }, records });
|
|
1686
|
+
if (made === null)
|
|
1687
|
+
throw new JobRefusal('operation_unavailable', 'studio cannot start a document from a chat on this daemon yet', 409);
|
|
1688
|
+
const shape = { card: card.id, option: r.option?.id ?? null, depth: null, by: facts.by, source: facts.source, ...(facts.guess !== undefined ? { guess: facts.guess } : {}) };
|
|
1689
|
+
const kindTok = { id: 'kind', kind: (card.variant !== undefined ? 'option' : 'card'), label: nounOf(card, shape.option), swap: null };
|
|
1690
|
+
const checksTok = { id: 'checks', kind: 'checks', label: checksLabel(r.resolved.gate), swap: null };
|
|
1691
|
+
return {
|
|
1692
|
+
...made,
|
|
1693
|
+
pid,
|
|
1694
|
+
turnId: ctx.turnId,
|
|
1695
|
+
// `what.entry` stays the document entry the create launcher reads its style from (codex r1); the card is in `shape`.
|
|
1696
|
+
shape,
|
|
1697
|
+
catalogRev: ctx.served.rev,
|
|
1698
|
+
resolution: r.resolved.resolution,
|
|
1699
|
+
launch: 'document',
|
|
1700
|
+
command: r.option?.command ?? card.command,
|
|
1701
|
+
gate: [...r.resolved.gate],
|
|
1702
|
+
words: facts.words,
|
|
1703
|
+
details: [...facts.details],
|
|
1704
|
+
sentence: { text: `I'll make {kind} from this conversation, filed in ${made.filedIn.label}, checked by {checks}.`, tokens: [kindTok, checksTok], notes: [...ctx.notes], ask: made.blocked === null ? 'Start?' : null },
|
|
1705
|
+
suggestions: [],
|
|
1706
|
+
question: null,
|
|
1707
|
+
revises: ctx.revises,
|
|
1708
|
+
lineage: ctx.lineage ?? pid,
|
|
1709
|
+
...(ctx.answers !== undefined ? { answers: ctx.answers } : {}),
|
|
1710
|
+
...(ctx.request !== undefined ? { request: ctx.request } : {}),
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
/** Resolve facts to the proposal of their kind (a job, or a document's create). */
|
|
1714
|
+
async proposalOf(chatId, pid, facts, ctx, records, allowHidden = false) {
|
|
1715
|
+
const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
|
|
1716
|
+
const r = card === undefined ? null : resolveOption(card.id, optionFor(card, facts.option), ctx.served);
|
|
1717
|
+
if (r !== null && proposalKindOf(r) === 'create')
|
|
1718
|
+
return this.documentProposal(chatId, pid, facts, ctx, records);
|
|
1719
|
+
return resolveJob(facts, ctx, { allowHidden });
|
|
1720
|
+
}
|
|
1721
|
+
refusalOf(err) {
|
|
1722
|
+
if (err instanceof JobRefusal)
|
|
1723
|
+
return { code: err.status, body: { code: err.code, error: err.message } };
|
|
1724
|
+
if (err instanceof EditRefusal)
|
|
1725
|
+
return { code: 400, body: { code: 'edits_invalid', error: err.message } };
|
|
1726
|
+
return null;
|
|
1727
|
+
}
|
|
1728
|
+
/**
|
|
1729
|
+
* `POST /chats/:id/proposals` after the route's capability, person and owner checks: a person-made proposal (a `/`
|
|
1730
|
+
* pick, a typed command, a question's choice) or a revision (a swap, a suggestion, a question's choice). No seat turn
|
|
1731
|
+
* runs. A repeated `requestId` answers the same proposal; another body under it is refused.
|
|
1732
|
+
*/
|
|
1733
|
+
propose(chatId, body, actor, instance) {
|
|
1734
|
+
return this.lock.run(`chat\u0000${instance ?? chatId}`, async () => {
|
|
1735
|
+
if (this.deps.instanceOf(chatId) !== instance)
|
|
1736
|
+
return this.gone(chatId);
|
|
1737
|
+
if (!this.jobsOn())
|
|
1738
|
+
return { code: 409, body: { code: 'operation_unavailable', error: 'this daemon does not take job proposals from a chat' } };
|
|
1739
|
+
const pid = personPid(chatId, actor.id, body.requestId);
|
|
1740
|
+
const digest = requestDigest(body);
|
|
1741
|
+
const records = this.deps.records(chatId);
|
|
1742
|
+
const held = foldProposals(records).get(pid);
|
|
1743
|
+
if (held !== undefined) {
|
|
1744
|
+
if (held.proposal.request?.digest === digest)
|
|
1745
|
+
return { code: 201, body: { view: viewOf(held) } };
|
|
1746
|
+
return { code: 409, body: { code: 'request_reused', error: 'this requestId already made a different proposal', view: viewOf(held) } };
|
|
1747
|
+
}
|
|
1748
|
+
try {
|
|
1749
|
+
if ('revises' in body) {
|
|
1750
|
+
return await this.reviseLocked(chatId, { revises: body.revises, edits: body.edits }, { person: actor, source: body.source, pid, request: { id: body.requestId, digest }, turnId: null, message: null }, instance);
|
|
1751
|
+
}
|
|
1752
|
+
const chat = this.jobChat(chatId);
|
|
1753
|
+
if (chat === null)
|
|
1754
|
+
return { code: 409, body: { code: 'chat_gone', error: `chat ${chatId} has ended; start a new one` } };
|
|
1755
|
+
// A command names its card (and maybe its option); an alias is the only way to a hidden card.
|
|
1756
|
+
let card = body.card;
|
|
1757
|
+
let option = body.option;
|
|
1758
|
+
let allowHidden = false;
|
|
1759
|
+
if (card.startsWith('/')) {
|
|
1760
|
+
const hit = parseCommand(card);
|
|
1761
|
+
if (hit === null)
|
|
1762
|
+
return { code: 400, body: { code: 'card_unknown', error: `no job has the command ${card.slice(0, 80)}` } };
|
|
1763
|
+
allowHidden = CATALOG_V2_CARDS.find((c) => c.id === hit.card)?.aliases.some((a) => a.command.toLowerCase() === card.trim().split(/\s+/u)[0].toLowerCase()) === true;
|
|
1764
|
+
card = hit.card;
|
|
1765
|
+
if (option === undefined && hit.option !== undefined)
|
|
1766
|
+
option = hit.option;
|
|
1767
|
+
}
|
|
1768
|
+
const facts = {
|
|
1769
|
+
card,
|
|
1770
|
+
option,
|
|
1771
|
+
depth: body.depth ?? null,
|
|
1772
|
+
words: (body.words ?? '').slice(0, 8000),
|
|
1773
|
+
details: [],
|
|
1774
|
+
repoRef: null,
|
|
1775
|
+
projectId: chat.projectId,
|
|
1776
|
+
lead: null,
|
|
1777
|
+
seats: null,
|
|
1778
|
+
inputs: {},
|
|
1779
|
+
skipQe: null,
|
|
1780
|
+
by: 'person',
|
|
1781
|
+
source: body.source,
|
|
1782
|
+
};
|
|
1783
|
+
const ctx = await this.jobContext(chatId, pid, null, 'person', chat, { revises: null, lineage: null, notes: [], request: { id: body.requestId, digest } });
|
|
1784
|
+
const proposal = await this.proposalOf(chatId, pid, facts, ctx, records, allowHidden);
|
|
1785
|
+
if (!this.write(chatId, { at: this.now(), turnId: `person:${pid.slice(pid.lastIndexOf(':') + 1)}`, kind: 'proposal', proposal }, instance))
|
|
1786
|
+
return this.gone(chatId);
|
|
1787
|
+
const view = foldProposals(this.deps.records(chatId)).get(pid);
|
|
1788
|
+
return { code: 201, body: { view: view !== undefined ? viewOf(view) : { proposal, state: 'open' } } };
|
|
1789
|
+
}
|
|
1790
|
+
catch (err) {
|
|
1791
|
+
const refused = this.refusalOf(err);
|
|
1792
|
+
if (refused !== null)
|
|
1793
|
+
return refused;
|
|
1794
|
+
throw err;
|
|
1795
|
+
}
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* A revision of the lineage's open proposal (§4.6), under the chat's lock: the stale-parent check, the merge, the
|
|
1800
|
+
* lost-check question, the re-resolution, and the write that supersedes the parent. `src.person` is the person's
|
|
1801
|
+
* route (only it takes `confirmLoss`); otherwise a seat's block bound to the person's message `src.turnId`.
|
|
1802
|
+
*/
|
|
1803
|
+
async reviseLocked(chatId, rev, src, instance) {
|
|
1804
|
+
const records = this.deps.records(chatId);
|
|
1805
|
+
const folded = foldProposals(records);
|
|
1806
|
+
const parent = folded.get(rev.revises);
|
|
1807
|
+
if (parent === undefined)
|
|
1808
|
+
return { code: 404, body: { error: `no proposal ${rev.revises} in chat ${chatId}` } };
|
|
1809
|
+
// The parent must be the lineage's open proposal: superseded, accepted, decided, or held by another turn is stale.
|
|
1810
|
+
const ownHold = parent.state === 'revising' && src.turnId !== null && parent.hold === src.turnId;
|
|
1811
|
+
if (!(parent.state === 'open' || ownHold)) {
|
|
1812
|
+
return { code: 409, body: { code: parent.state === 'revising' ? 'proposal_revising' : 'proposal_stale', error: parent.state === 'revising' ? 'your typed change is still being applied; wait for it' : 'this proposal is no longer the open one in this chat', view: viewOf(parent) } };
|
|
1813
|
+
}
|
|
1814
|
+
if (parent.proposal.shape === undefined)
|
|
1815
|
+
return { code: 400, body: { code: 'edits_invalid', error: 'only a job proposal is revised this way' } };
|
|
1816
|
+
const chat = this.jobChat(chatId);
|
|
1817
|
+
if (chat === null)
|
|
1818
|
+
return { code: 409, body: { code: 'chat_gone', error: `chat ${chatId} has ended; start a new one` } };
|
|
1819
|
+
const fromPerson = src.person !== null;
|
|
1820
|
+
// Only the person's own press can give up a check.
|
|
1821
|
+
const edits = { ...rev.edits };
|
|
1822
|
+
// What the press confirms (codex r4): `true` on a lost-check question covers exactly what that question names; a
|
|
1823
|
+
// swap or suggestion carries the ids its own label named. Anything else covers nothing.
|
|
1824
|
+
const confirmIds = !fromPerson || edits.confirmLoss === undefined
|
|
1825
|
+
? null
|
|
1826
|
+
: Array.isArray(edits.confirmLoss)
|
|
1827
|
+
? new Set(edits.confirmLoss)
|
|
1828
|
+
: parent.proposal.question?.kind === 'lost_check'
|
|
1829
|
+
? new Set([...(parent.proposal.question.lost ?? []), ...(parent.proposal.question.lostSeats ?? [])])
|
|
1830
|
+
: new Set();
|
|
1831
|
+
const confirmed = confirmIds !== null;
|
|
1832
|
+
delete edits.confirmLoss;
|
|
1833
|
+
const ctx0 = await this.jobContext(chatId, src.pid, src.turnId, fromPerson ? 'person' : (parent.proposal.seat ?? 'seat'), chat, {
|
|
1834
|
+
revises: parent.proposal.pid,
|
|
1835
|
+
lineage: parent.proposal.lineage ?? parent.proposal.pid,
|
|
1836
|
+
notes: [],
|
|
1837
|
+
...(src.turnId !== null ? { answers: src.turnId } : {}),
|
|
1838
|
+
...(src.request !== undefined ? { request: src.request } : {}),
|
|
1839
|
+
});
|
|
1840
|
+
// A QE skip is never applied from a seat's block (§4.6 step 7, §9.2 (ac)): it becomes wicked's question, with the
|
|
1841
|
+
// person's own reason when their message (the one this turn answers) gives one unquoted, else asking for it. A skip
|
|
1842
|
+
// the person never asked for in their own words changes nothing. On the person's route, only the press applies it.
|
|
1843
|
+
let qe = null;
|
|
1844
|
+
const extraNotes = [];
|
|
1845
|
+
if (edits.skipQe !== undefined && !confirmed) {
|
|
1846
|
+
const reason = edits.skipQe.reason;
|
|
1847
|
+
delete edits.skipQe;
|
|
1848
|
+
if (parent.proposal.gate?.includes('qe-acceptance') !== true)
|
|
1849
|
+
extraNotes.push('Not changed: this job has no QE acceptance to skip.');
|
|
1850
|
+
else if (fromPerson || qeSkipBound(reason, src.message))
|
|
1851
|
+
qe = { reason };
|
|
1852
|
+
else if (personAskedSkip(src.message))
|
|
1853
|
+
qe = { reason: null };
|
|
1854
|
+
else
|
|
1855
|
+
extraNotes.push('Not changed: QE acceptance stays. Skipping it needs your own reason, in your own words.');
|
|
1856
|
+
}
|
|
1857
|
+
const merged = mergeRevision(parent.proposal, edits, { chat, served: ctx0.served, roster: ctx0.roster });
|
|
1858
|
+
merged.notes.push(...extraNotes);
|
|
1859
|
+
const ctx = { ...ctx0, notes: merged.notes };
|
|
1860
|
+
// A hidden card stays reachable while the revision keeps it (it was reached by its alias once).
|
|
1861
|
+
const allowHidden = merged.facts.card === parent.proposal.shape.card;
|
|
1862
|
+
// The candidate as it would be written, settings included (a daemon's QE setting can drop QE from it): its checks
|
|
1863
|
+
// are compared with the parent's too, so nothing is lost unseen (codex r2).
|
|
1864
|
+
let candidate = null;
|
|
1865
|
+
let candidateErr = null;
|
|
1866
|
+
try {
|
|
1867
|
+
candidate = keepReshape(await this.proposalOf(chatId, src.pid, { ...merged.facts, by: fromPerson ? 'person' : merged.facts.by, source: src.source }, ctx, records, allowHidden), parent.proposal);
|
|
1868
|
+
}
|
|
1869
|
+
catch (err) {
|
|
1870
|
+
candidateErr = err;
|
|
1871
|
+
}
|
|
1872
|
+
// Losses only the fully resolved candidate shows (a daemon setting since): never covered by an earlier press.
|
|
1873
|
+
const extra = [];
|
|
1874
|
+
for (const g of parent.proposal.gate ?? [])
|
|
1875
|
+
if (candidate !== null && !(candidate.gate ?? []).includes(g) && !merged.lost.includes(g) && !(g === 'qe-acceptance' && merged.facts.skipQe !== null))
|
|
1876
|
+
extra.push(g);
|
|
1877
|
+
merged.lost.push(...extra);
|
|
1878
|
+
const loses = merged.lost.length > 0 || merged.lostSeats.length > 0;
|
|
1879
|
+
// A press confirms exactly what was disclosed to it (codex r3): the question's named losses, or a swap's own
|
|
1880
|
+
// (catalog-derived, named in its label). A loss beyond that asks again.
|
|
1881
|
+
const uncovered = confirmIds === null ? [...merged.lost, ...merged.lostSeats] : [...merged.lost, ...merged.lostSeats].filter((k) => !confirmIds.has(k));
|
|
1882
|
+
const covered = confirmed && uncovered.length === 0;
|
|
1883
|
+
// A candidate the daemon cannot make is said at once, never behind a question it could not honour (codex r4, r5):
|
|
1884
|
+
// a refusal, or a candidate blocked for a reason no answer fixes (unavailable, coming).
|
|
1885
|
+
if (candidate === null && candidateErr !== null && loses && !covered) {
|
|
1886
|
+
const refused = this.refusalOf(candidateErr);
|
|
1887
|
+
if (refused !== null)
|
|
1888
|
+
return refused;
|
|
1889
|
+
}
|
|
1890
|
+
// Unmakeable = coming, or blocked for a reason other than the one question an answer fixes (codex r6).
|
|
1891
|
+
const unmakeable = candidate !== null && (candidate.coming !== undefined || (candidate.blocked !== null && candidate.blocked !== (candidate.question?.text ?? null)));
|
|
1892
|
+
if (candidate !== null && loses && !covered && unmakeable) {
|
|
1893
|
+
return { code: 409, body: { code: 'card_not_available', error: candidate.blocked, view: viewOf(parent) } };
|
|
1894
|
+
}
|
|
1895
|
+
if (qe !== null || (loses && !covered)) {
|
|
1896
|
+
const base = keepReshape(await this.proposalOf(chatId, src.pid, factsOf(parent.proposal), ctx, records, true), parent.proposal);
|
|
1897
|
+
const newCard = CATALOG_V2_CARDS.find((c) => c.id === merged.facts.card);
|
|
1898
|
+
const oldCard = CATALOG_V2_CARDS.find((c) => c.id === parent.proposal.shape.card);
|
|
1899
|
+
const newNoun = nounOf(newCard, optionFor(newCard, merged.facts.option));
|
|
1900
|
+
const oldNoun = nounOf(oldCard, parent.proposal.shape.option);
|
|
1901
|
+
// The choice carries exactly the edits crew kept (codex r1: never a refused seat skip), plus the press.
|
|
1902
|
+
const lossEdit = { ...edits, confirmLoss: true };
|
|
1903
|
+
let question;
|
|
1904
|
+
if (qe !== null && !loses) {
|
|
1905
|
+
question = qe.reason === null
|
|
1906
|
+
? { kind: 'lost_check', text: 'Skip QE acceptance? Say why, and the job will be labelled with your reason.', choices: [{ label: 'Keep QE', edit: {} }], lost: ['qe-acceptance'], input: { kind: 'text', label: 'Your reason', edit: 'skipQe.reason' } }
|
|
1907
|
+
: { kind: 'lost_check', text: `Skip QE acceptance? The job will be labelled with your reason: “${qe.reason}”.`, choices: [{ label: 'Skip it', edit: { ...lossEdit, skipQe: { reason: qe.reason } } }, { label: 'Keep QE', edit: {} }], lost: ['qe-acceptance'] };
|
|
1908
|
+
}
|
|
1909
|
+
else {
|
|
1910
|
+
const lost = qe?.reason !== null && qe !== null ? [...new Set(['qe-acceptance', ...merged.lost])] : merged.lost;
|
|
1911
|
+
const choice = qe !== null && qe.reason !== null ? { ...lossEdit, skipQe: { reason: qe.reason } } : lossEdit;
|
|
1912
|
+
const words = [...lost.map((g) => checksLabel([g])), ...merged.lostSeats.map((k) => SEAT_WORDS[k])];
|
|
1913
|
+
const lostText = words.length <= 1 ? (words[0] ?? '') : `${words.slice(0, -1).join(', ')} and ${words[words.length - 1]}`;
|
|
1914
|
+
question = {
|
|
1915
|
+
kind: 'lost_check',
|
|
1916
|
+
text: newNoun === oldNoun ? `That would no longer have ${lostText}. Change it anyway?` : `That's ${newNoun}, not ${oldNoun}: it would no longer have ${lostText}. Make it ${newNoun}?`,
|
|
1917
|
+
choices: [{ label: newNoun === oldNoun ? 'Change it' : `Make it ${newNoun}`, edit: choice }, { label: `Keep ${oldNoun}`, edit: {} }],
|
|
1918
|
+
lost,
|
|
1919
|
+
...(merged.lostSeats.length > 0 ? { lostSeats: merged.lostSeats } : {}),
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
const asked = {
|
|
1923
|
+
...base,
|
|
1924
|
+
// The baseline stays what the person saw (codex r3): a later unrelated revision compares against it.
|
|
1925
|
+
gate: [...new Set([...(parent.proposal.gate ?? []), ...(base.gate ?? [])])],
|
|
1926
|
+
seatRules: [...new Set([...(parent.proposal.seatRules ?? []), ...(base.seatRules ?? [])])],
|
|
1927
|
+
question,
|
|
1928
|
+
suggestions: [],
|
|
1929
|
+
blocked: question.text,
|
|
1930
|
+
...(base.sentence !== undefined ? { sentence: { ...base.sentence, ask: question.text } } : {}),
|
|
1931
|
+
};
|
|
1932
|
+
if (!this.write(chatId, { at: this.now(), turnId: src.turnId ?? `person:${src.pid.slice(src.pid.lastIndexOf(':') + 1)}`, kind: 'proposal', proposal: asked }, instance))
|
|
1933
|
+
return this.gone(chatId);
|
|
1934
|
+
const view = foldProposals(this.deps.records(chatId)).get(src.pid);
|
|
1935
|
+
return { code: 201, body: { view: view !== undefined ? viewOf(view) : { proposal: asked, state: 'open' } } };
|
|
1936
|
+
}
|
|
1937
|
+
// A seat's revision that changes nothing and says nothing re-proposes nothing ("skip parity": the seat says why).
|
|
1938
|
+
if (!fromPerson && merged.unchanged && merged.notes.length === 0)
|
|
1939
|
+
return { code: 200, body: { view: viewOf(parent) } };
|
|
1940
|
+
if (candidate === null)
|
|
1941
|
+
throw candidateErr;
|
|
1942
|
+
const proposal = candidate;
|
|
1943
|
+
if (!this.write(chatId, { at: this.now(), turnId: src.turnId ?? `person:${src.pid.slice(src.pid.lastIndexOf(':') + 1)}`, kind: 'proposal', proposal }, instance))
|
|
1944
|
+
return this.gone(chatId);
|
|
1945
|
+
const view = foldProposals(this.deps.records(chatId)).get(src.pid);
|
|
1946
|
+
return { code: 201, body: { view: view !== undefined ? viewOf(view) : { proposal, state: 'open' } } };
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* The person's message `turnId` was written (`POST /chats/:id/messages`): the chat's open job proposal is held as
|
|
1950
|
+
* `revising` until that turn settles, under the lock Go takes, so a Go is either before the message (and launches
|
|
1951
|
+
* what was on screen) or after it (and waits).
|
|
1952
|
+
*/
|
|
1953
|
+
holdForMessage(chatId, turnId) {
|
|
1954
|
+
const instance = this.deps.instanceOf(chatId);
|
|
1955
|
+
const key = `${chatId}\u0000${turnId}`;
|
|
1956
|
+
const done = this.lock.run(`chat\u0000${instance ?? chatId}`, async () => {
|
|
1957
|
+
if (!this.jobsOn() || this.deps.instanceOf(chatId) !== instance)
|
|
1958
|
+
return;
|
|
1959
|
+
for (const f of foldProposals(this.deps.records(chatId)).values()) {
|
|
1960
|
+
if (f.state !== 'open' || f.proposal.shape === undefined)
|
|
1961
|
+
continue;
|
|
1962
|
+
this.write(chatId, { at: this.now(), turnId, kind: 'proposal_revising', pid: f.proposal.pid }, instance);
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
this.holding.set(key, done);
|
|
1966
|
+
void done.finally(() => {
|
|
1967
|
+
if (this.holding.get(key) === done)
|
|
1968
|
+
this.holding.delete(key);
|
|
1969
|
+
}).catch(() => undefined);
|
|
1970
|
+
return done;
|
|
1971
|
+
}
|
|
1972
|
+
/**
|
|
1973
|
+
* A seat's reply to a turn that holds a job proposal: its revision block (bound to that turn's message) is merged and
|
|
1974
|
+
* published, or refused; either way, and when the turn wrote none or failed, the hold ends.
|
|
1975
|
+
*/
|
|
1976
|
+
onTurnReply(frame) {
|
|
1977
|
+
const turnId = frame.turnId;
|
|
1978
|
+
if (turnId === undefined || !this.jobsOn())
|
|
1979
|
+
return;
|
|
1980
|
+
// Answered, not gone: a read must not release this hold while its revision is still queued (codex r1).
|
|
1981
|
+
const key = `${frame.chat}\u0000${turnId}`;
|
|
1982
|
+
this.settling.set(key, (this.settling.get(key) ?? 0) + 1);
|
|
1983
|
+
const instance = this.deps.instanceOf(frame.chat);
|
|
1984
|
+
const job = this.order.run(`chat\u0000${frame.chat}`, async () => {
|
|
1985
|
+
// The hold is written with the person's message, which can land just after a fast reply.
|
|
1986
|
+
const heldBy = () => [...foldProposals(this.deps.records(frame.chat)).values()].find((f) => f.state === 'revising' && f.hold === turnId);
|
|
1987
|
+
for (let i = 0; i < 25 && heldBy() === undefined && !this.deps.records(frame.chat).some((r) => r.kind === 'user' && r.turnId === turnId); i += 1) {
|
|
1988
|
+
await new Promise((res) => setTimeout(res, 200));
|
|
1989
|
+
}
|
|
1990
|
+
// The hold is enqueued with the message; a fast reply waits for it to be written, not only for the message.
|
|
1991
|
+
await this.holding.get(`${frame.chat}\u0000${turnId}`);
|
|
1992
|
+
if (heldBy() === undefined)
|
|
1993
|
+
return;
|
|
1994
|
+
await this.lock.run(`chat\u0000${instance ?? frame.chat}`, async () => {
|
|
1995
|
+
if (this.deps.instanceOf(frame.chat) !== instance)
|
|
1996
|
+
return;
|
|
1997
|
+
const held = heldBy();
|
|
1998
|
+
if (held === undefined)
|
|
1999
|
+
return;
|
|
2000
|
+
let note = frame.ok ? null : "Your change wasn't applied: say it again.";
|
|
2001
|
+
if (frame.ok) {
|
|
2002
|
+
let rev = null;
|
|
2003
|
+
for (let i = frame.blocks.length - 1; i >= 0 && rev === null; i -= 1)
|
|
2004
|
+
rev = parseRevisionBlock(frame.blocks[i]);
|
|
2005
|
+
if (rev !== null && rev.revises === held.proposal.pid) {
|
|
2006
|
+
const message = this.deps.records(frame.chat).find((r) => r.kind === 'user' && r.turnId === turnId && r.owner === true)?.text ?? null;
|
|
2007
|
+
try {
|
|
2008
|
+
const out = await this.reviseLocked(frame.chat, rev, { person: null, source: 'chat', pid: `${frame.chat}:${turnId}`, turnId, message }, instance);
|
|
2009
|
+
if (out.code >= 400)
|
|
2010
|
+
this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s revision was refused (${String(out.body.code ?? out.code)})`);
|
|
2011
|
+
}
|
|
2012
|
+
catch (err) {
|
|
2013
|
+
note = "Your change wasn't applied: say it again.";
|
|
2014
|
+
this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s revision failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
else if (rev !== null) {
|
|
2018
|
+
this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s revision names ${rev.revises}, not the proposal its message held — dropped`);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
// Released whatever happened (a published revision supersedes the parent; the record is then a no-op).
|
|
2022
|
+
this.write(frame.chat, { at: this.now(), turnId, kind: 'proposal_released', pid: held.proposal.pid, note }, instance);
|
|
2023
|
+
});
|
|
2024
|
+
})
|
|
2025
|
+
.catch((err) => this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s hold could not be settled: ${err instanceof Error ? err.message : String(err)}`))
|
|
2026
|
+
.finally(() => {
|
|
2027
|
+
this.pending.delete(job);
|
|
2028
|
+
const n = (this.settling.get(key) ?? 1) - 1;
|
|
2029
|
+
if (n <= 0)
|
|
2030
|
+
this.settling.delete(key);
|
|
2031
|
+
else
|
|
2032
|
+
this.settling.set(key, n);
|
|
2033
|
+
});
|
|
2034
|
+
this.pending.add(job);
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* A hold whose turn is no longer live (it failed or expired, or a restart forgot it) is released with a note, so the
|
|
2038
|
+
* proposal is startable again. Called by a Go and by a read of the chat. `true` when one was released.
|
|
2039
|
+
*/
|
|
2040
|
+
async reopenStale(chatId, instance = this.deps.instanceOf(chatId)) {
|
|
2041
|
+
if (this.deps.turnLive === undefined)
|
|
2042
|
+
return false;
|
|
2043
|
+
const gone = (turnId) => !this.deps.turnLive(chatId, turnId) && !this.settling.has(`${chatId}\u0000${turnId}`);
|
|
2044
|
+
const stale = [...foldProposals(this.deps.records(chatId)).values()].filter((f) => f.state === 'revising' && f.hold !== undefined && gone(f.hold));
|
|
2045
|
+
if (stale.length === 0)
|
|
2046
|
+
return false;
|
|
2047
|
+
return this.lock.run(`chat\u0000${instance ?? chatId}`, async () => {
|
|
2048
|
+
let released = false;
|
|
2049
|
+
for (const f of foldProposals(this.deps.records(chatId)).values()) {
|
|
2050
|
+
if (f.state !== 'revising' || f.hold === undefined || !gone(f.hold))
|
|
2051
|
+
continue;
|
|
2052
|
+
released = this.write(chatId, { at: this.now(), turnId: f.hold, kind: 'proposal_released', pid: f.proposal.pid, note: "Your change wasn't applied: say it again." }, instance) || released;
|
|
2053
|
+
}
|
|
2054
|
+
return released;
|
|
2055
|
+
});
|
|
2056
|
+
}
|
|
2057
|
+
/** A job's Go edits (option, depth, repository, seats, inputs) merged by the revision rules: one that loses a check
|
|
2058
|
+
* is refused (that is the person's press on the lost-check question, not an edit at Go). */
|
|
2059
|
+
async applyJobEdits(chatId, f, edits) {
|
|
2060
|
+
const allowed = ['option', 'depth', 'repoRef', 'seats', 'inputs'];
|
|
2061
|
+
for (const k of Object.keys(edits))
|
|
2062
|
+
if (!allowed.includes(k))
|
|
2063
|
+
throw new EditRefusal(`${k} can't be changed on a job proposal`);
|
|
2064
|
+
const chat = this.jobChat(chatId);
|
|
2065
|
+
if (chat === null)
|
|
2066
|
+
throw new EditRefusal('this chat has ended');
|
|
2067
|
+
const rev = {
|
|
2068
|
+
...(edits.option !== undefined ? { option: edits.option } : {}),
|
|
2069
|
+
...(edits.depth !== undefined ? { depth: edits.depth } : {}),
|
|
2070
|
+
...(edits.repoRef !== undefined ? { repoRef: edits.repoRef } : {}),
|
|
2071
|
+
...(edits.inputs !== undefined ? { inputs: edits.inputs } : {}),
|
|
2072
|
+
};
|
|
2073
|
+
const ctx = await this.jobContext(chatId, f.proposal.pid, f.proposal.turnId, f.proposal.seat, chat, { revises: f.proposal.revises ?? null, lineage: f.proposal.lineage ?? f.proposal.pid, notes: [] });
|
|
2074
|
+
const merged = mergeRevision(f.proposal, rev, { chat, served: ctx.served, roster: ctx.roster });
|
|
2075
|
+
if (edits.seats !== undefined) {
|
|
2076
|
+
const sr = f.proposal.shape === undefined ? null : resolveOption(f.proposal.shape.card, f.proposal.shape.option, ctx.served);
|
|
2077
|
+
if (sr?.workflow !== null && sr?.workflow !== undefined && SELF_SEATED.has(sr.workflow))
|
|
2078
|
+
throw new EditRefusal(`${f.proposal.what.title} picks its own seat`);
|
|
2079
|
+
const can = new Set(ctx.roster.map((s) => s.key));
|
|
2080
|
+
if (edits.seats.length === 0 || edits.seats.some((k) => !can.has(k)))
|
|
2081
|
+
throw new EditRefusal('pick seats that can work now');
|
|
2082
|
+
merged.facts.seats = [...new Set(edits.seats)];
|
|
2083
|
+
merged.facts.lead = edits.seats[0];
|
|
2084
|
+
}
|
|
2085
|
+
if (merged.notes.length > 0)
|
|
2086
|
+
throw new EditRefusal(merged.notes[0]);
|
|
2087
|
+
if (merged.lost.length > 0 || merged.lostSeats.length > 0) {
|
|
2088
|
+
throw new EditRefusal(`that would drop ${[...merged.lost.map((g) => checksLabel([g])), ...merged.lostSeats.map((k) => SEAT_WORDS[k])].join(', ')}; ask for it in the chat`);
|
|
2089
|
+
}
|
|
2090
|
+
const out = keepReshape(await this.proposalOf(chatId, f.proposal.pid, merged.facts, ctx, this.deps.records(chatId), merged.facts.card === f.proposal.shape?.card), f.proposal);
|
|
2091
|
+
if (out.kind !== 'job')
|
|
2092
|
+
throw new EditRefusal('that option makes a document: pick it in the chat');
|
|
2093
|
+
const dropped = (f.proposal.gate ?? []).filter((g) => !(out.gate ?? []).includes(g));
|
|
2094
|
+
if (dropped.length > 0)
|
|
2095
|
+
throw new EditRefusal(`that would drop ${checksLabel(dropped)}; check the job again`);
|
|
2096
|
+
if (out.seats !== undefined && out.shape !== undefined) {
|
|
2097
|
+
const r = resolveOption(out.shape.card, out.shape.option, ctx.served);
|
|
2098
|
+
if (r !== null && !(r.workflow !== null && SELF_SEATED.has(r.workflow)) && out.seats.keys.length < 1 + (r.resolved.seats.distinctEvaluator ? 1 : 0) + (r.resolved.seats.distinctJudge ? 1 : 0)) {
|
|
2099
|
+
throw new EditRefusal('this job needs another seat to check the one that builds');
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
return out;
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Go on a job (§4.6): the frozen catalog revision and resolution are compared with the current catalog first; a
|
|
2106
|
+
* mismatch records the refreshed proposal (superseding this one) and answers 409 `catalog_changed`.
|
|
2107
|
+
*/
|
|
2108
|
+
async jobStale(chatId, f0, instance) {
|
|
2109
|
+
// Re-read under the chat's lock: a revision that won the lock first made this one stale (codex r1).
|
|
2110
|
+
const f = foldProposals(this.deps.records(chatId)).get(f0.proposal.pid);
|
|
2111
|
+
if (f === undefined || f.state !== f0.state) {
|
|
2112
|
+
return { code: 409, body: { code: 'proposal_stale', error: 'this proposal changed while it was being started; check it again', ...(f !== undefined ? { view: viewOf(f) } : {}) } };
|
|
2113
|
+
}
|
|
2114
|
+
const p = f.state === 'accepting' && f.accepting !== undefined ? f.accepting.resolution : f.proposal;
|
|
2115
|
+
if (p.shape === undefined)
|
|
2116
|
+
return null;
|
|
2117
|
+
// A chat that has ended is re-checked from the proposal's own facts (codex r2): the check never depends on it being open.
|
|
2118
|
+
const chat = this.jobChat(chatId) ?? {
|
|
2119
|
+
projectId: p.filedIn.projectId,
|
|
2120
|
+
repos: (p.repoRefs ?? []).map((id, i) => ({ id, name: p.repos[i] ?? id })),
|
|
2121
|
+
lead: p.seats?.lead ?? null,
|
|
2122
|
+
seats: p.seats?.keys ?? [],
|
|
2123
|
+
};
|
|
2124
|
+
const pid = `${p.pid}:c:${this.now().toString(36)}`;
|
|
2125
|
+
let ctx;
|
|
2126
|
+
try {
|
|
2127
|
+
ctx = await this.jobContext(chatId, pid, p.turnId, p.seat, chat, { revises: p.pid, lineage: p.lineage ?? p.pid, notes: ['The catalog changed since this was proposed: check it again before starting.'] });
|
|
2128
|
+
}
|
|
2129
|
+
catch (err) {
|
|
2130
|
+
const refused = this.refusalOf(err);
|
|
2131
|
+
if (refused !== null)
|
|
2132
|
+
return refused;
|
|
2133
|
+
throw err;
|
|
2134
|
+
}
|
|
2135
|
+
const card = CATALOG_V2_CARDS.find((c) => c.id === p.shape.card);
|
|
2136
|
+
const r = card === undefined ? null : resolveOption(card.id, optionFor(card, p.shape.option), ctx.served);
|
|
2137
|
+
if (r !== null && ctx.served.rev === p.catalogRev && r.resolved.resolution === p.resolution)
|
|
2138
|
+
return null;
|
|
2139
|
+
let fresh;
|
|
2140
|
+
try {
|
|
2141
|
+
fresh = keepReshape(await this.proposalOf(chatId, pid, factsOf(p), ctx, this.deps.records(chatId), true), p);
|
|
2142
|
+
}
|
|
2143
|
+
catch (err) {
|
|
2144
|
+
const refused = this.refusalOf(err);
|
|
2145
|
+
if (refused !== null)
|
|
2146
|
+
return { code: 409, body: { code: 'catalog_changed', error: `the catalog changed since this was proposed: ${String(refused.body['error'])}`, view: viewOf(f) } };
|
|
2147
|
+
throw err;
|
|
2148
|
+
}
|
|
2149
|
+
// A refresh that would carry fewer checks (or seat protections) than the proposal on screen is not startable until
|
|
2150
|
+
// the person presses the question naming what changed (codex r1).
|
|
2151
|
+
const lost = (p.gate ?? []).filter((g) => !(fresh.gate ?? []).includes(g));
|
|
2152
|
+
const lostSeats = (p.seatRules ?? []).filter((k) => !(fresh.seatRules ?? []).includes(k));
|
|
2153
|
+
if ((lost.length > 0 || lostSeats.length > 0) && fresh.kind === 'job') {
|
|
2154
|
+
const words = [...lost.map((g) => checksLabel([g])), ...lostSeats.map((k) => SEAT_WORDS[k])].join(', ');
|
|
2155
|
+
const text = `The catalog changed: this job would no longer have ${words}. Start it like that?`;
|
|
2156
|
+
// The baseline stays the proposal the person saw, so an unrelated revision cannot clear the question (codex r2).
|
|
2157
|
+
fresh = { ...fresh, gate: [...new Set([...(fresh.gate ?? []), ...lost])], seatRules: [...new Set([...(fresh.seatRules ?? []), ...lostSeats])], question: { kind: 'lost_check', text, choices: [{ label: 'Accept the change', edit: { confirmLoss: true } }], lost, ...(lostSeats.length > 0 ? { lostSeats } : {}) }, suggestions: [], blocked: text, ...(fresh.sentence !== undefined ? { sentence: { ...fresh.sentence, ask: text } } : {}) };
|
|
2158
|
+
}
|
|
2159
|
+
if (!this.write(chatId, { at: this.now(), turnId: f.turnId, kind: 'proposal', proposal: fresh }, instance))
|
|
2160
|
+
return this.gone(chatId);
|
|
2161
|
+
const after = foldProposals(this.deps.records(chatId)).get(pid);
|
|
2162
|
+
return { code: 409, body: { code: 'catalog_changed', error: 'the catalog changed since this was proposed; check the job again and press Start', ...(after !== undefined ? { view: viewOf(after) } : {}) } };
|
|
2163
|
+
}
|
|
2164
|
+
/**
|
|
2165
|
+
* `POST /runs/:id/reshape` (§2.5) after the route's checks (a person, the chat is theirs, the run is held at its first
|
|
2166
|
+
* work-plan approval): under the chat's lock, so another proposal's Start waits for it — the crew-made reshape
|
|
2167
|
+
* proposal `<chatId>:reshape:<run>:<requestId>` is written (or found: a repeated request is idempotent), validated
|
|
2168
|
+
* against the held job's checks, then Go's one reshape transition (preflight, the held plan answered Reject through
|
|
2169
|
+
* `deps.reshapeReject`, `heldRejected` recorded, the launch). A failed launch after the Reject leaves it accepting:
|
|
2170
|
+
* the same request, or Go on it, tries again.
|
|
2171
|
+
*/
|
|
2172
|
+
reshape(chatId, x, actor, instance) {
|
|
2173
|
+
return this.lock.run(`pid\u0000${x.pid}`, () => this.lock.run(`chat\u0000${instance ?? chatId}`, async () => {
|
|
2174
|
+
if (this.deps.instanceOf(chatId) !== instance)
|
|
2175
|
+
return this.gone(chatId);
|
|
2176
|
+
if (!this.jobsOn())
|
|
2177
|
+
return { code: 409, body: { code: 'operation_unavailable', error: 'this daemon does not start jobs from a chat' } };
|
|
2178
|
+
let folded = foldProposals(this.deps.records(chatId)).get(x.pid);
|
|
2179
|
+
if (folded !== undefined && folded.proposal.request?.digest !== x.request.digest) {
|
|
2180
|
+
return { code: 409, body: { code: 'request_reused', error: 'this requestId already started the run again as something else', view: viewOf(folded) } };
|
|
2181
|
+
}
|
|
2182
|
+
if (folded?.state === 'decided') {
|
|
2183
|
+
return folded.decision === 'go' ? { code: 200, body: { view: viewOf(folded) } } : { code: 409, body: { code: 'proposal_decided', error: 'this reshape was answered Not now', view: viewOf(folded) } };
|
|
2184
|
+
}
|
|
2185
|
+
if (folded === undefined) {
|
|
2186
|
+
const chat = this.jobChat(chatId);
|
|
2187
|
+
if (chat === null)
|
|
2188
|
+
return { code: 409, body: { code: 'chat_gone', error: `chat ${chatId} has ended; start a new one` } };
|
|
2189
|
+
const parent = x.parentPid === null ? undefined : foldProposals(this.deps.records(chatId)).get(x.parentPid);
|
|
2190
|
+
let proposal;
|
|
2191
|
+
try {
|
|
2192
|
+
const ctx = await this.jobContext(chatId, x.pid, null, 'person', chat, {
|
|
2193
|
+
revises: x.parentPid,
|
|
2194
|
+
lineage: parent?.proposal.lineage ?? x.parentPid ?? x.pid,
|
|
2195
|
+
notes: x.reducedAssurance ? ['Reduced assurance, as the held run had it.'] : [],
|
|
2196
|
+
request: x.request,
|
|
2197
|
+
});
|
|
2198
|
+
// The held job's proposal, merged by the revision rules (its inputs validated against the new card, what
|
|
2199
|
+
// the new card does not take dropped with a note; codex r2). A QE skip is never carried.
|
|
2200
|
+
const heldP = parent?.accepting?.resolution ?? parent?.proposal;
|
|
2201
|
+
let facts = x.facts;
|
|
2202
|
+
if (heldP?.shape !== undefined) {
|
|
2203
|
+
const merged = mergeRevision(heldP, x.edits, { chat, served: ctx.served, roster: ctx.roster });
|
|
2204
|
+
// Nothing is answered for a shape, or an input, that is not the one asked for (codex r3, r4).
|
|
2205
|
+
const wantCard = CATALOG_V2_CARDS.find((c) => c.id === (x.edits.card ?? merged.facts.card));
|
|
2206
|
+
const norm = (o) => (wantCard === undefined ? null : o === null || o === undefined ? (wantCard.variant?.default ?? null) : o);
|
|
2207
|
+
const optionOk = wantCard !== undefined && (x.edits.option === undefined || norm(merged.facts.option) === norm(x.edits.option));
|
|
2208
|
+
const depthOk = x.edits.depth === undefined || x.edits.depth === null || merged.facts.depth === x.edits.depth;
|
|
2209
|
+
const inputsOk = Object.entries(x.edits.inputs ?? {}).every(([k, v]) => (k === 'intent' ? merged.facts.words === (v.kind === 'text' ? v.value.slice(0, 8000) : '') : JSON.stringify(merged.facts.inputs[k]) === JSON.stringify(v)));
|
|
2210
|
+
if (wantCard === undefined || merged.facts.card !== wantCard.id || !optionOk || !depthOk || !inputsOk) {
|
|
2211
|
+
return { code: 400, body: { code: 'edits_invalid', error: merged.notes[0] ?? `there is no ${String(x.edits.card)}${x.edits.option !== undefined && x.edits.option !== null ? ` · ${String(x.edits.option)}` : ''} to start it again as`, notes: merged.notes } };
|
|
2212
|
+
}
|
|
2213
|
+
facts = { ...merged.facts, skipQe: null, by: 'person', source: 'reshape' };
|
|
2214
|
+
ctx.notes.push(...merged.notes);
|
|
2215
|
+
}
|
|
2216
|
+
proposal = await this.proposalOf(chatId, x.pid, facts, ctx, this.deps.records(chatId));
|
|
2217
|
+
}
|
|
2218
|
+
catch (err) {
|
|
2219
|
+
const refused = this.refusalOf(err);
|
|
2220
|
+
if (refused !== null)
|
|
2221
|
+
return refused;
|
|
2222
|
+
throw err;
|
|
2223
|
+
}
|
|
2224
|
+
if (proposal.kind !== 'job')
|
|
2225
|
+
return { code: 400, body: { code: 'shape_mismatch', error: 'a held run starts again as another job, not a document' } };
|
|
2226
|
+
// The held job's checks and seat protections are the parent's; a replacement with fewer is started only on the
|
|
2227
|
+
// person's press naming them (§2.5: the reshape question names the checks given up; codex r1).
|
|
2228
|
+
const held = parent?.accepting?.resolution ?? parent?.proposal;
|
|
2229
|
+
if (held !== undefined) {
|
|
2230
|
+
const lost = (held.gate ?? []).filter((g) => !(proposal.gate ?? []).includes(g));
|
|
2231
|
+
const heldCard = held.shape === undefined ? null : CATALOG_V2_CARDS.find((c) => c.id === held.shape.card) ?? null;
|
|
2232
|
+
const before = held.seatRules ?? (heldCard === null ? [] : seatProtections(resolveOption(heldCard.id, optionFor(heldCard, held.shape.option), (await this.deps.served(chat.projectId)))));
|
|
2233
|
+
const after = proposal.seatRules ?? [];
|
|
2234
|
+
const lostSeats = before.filter((k) => !after.includes(k));
|
|
2235
|
+
// Confirmed only for exactly what the person was shown (a loss since asks again; codex r4).
|
|
2236
|
+
if ([...lost, ...lostSeats].some((k) => !x.confirmLoss.includes(k))) {
|
|
2237
|
+
const words = [...lost.map((g) => checksLabel([g])), ...lostSeats.map((k) => SEAT_WORDS[k])];
|
|
2238
|
+
return { code: 409, body: { code: 'reshape_loses_check', error: `started again like that, it would no longer have ${words.join(', ')}: confirm to give ${words.length === 1 ? 'it' : 'them'} up`, lost, lostSeats } };
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
proposal = { ...proposal, reshapes: x.oldRunId, relaunch: x.relaunch, ...(x.reducedAssurance ? { reducedAssurance: true } : {}) };
|
|
2242
|
+
if (!this.write(chatId, { at: this.now(), turnId: `reshape:${x.oldRunId}`, kind: 'proposal', proposal }, instance))
|
|
2243
|
+
return this.gone(chatId);
|
|
2244
|
+
folded = foldProposals(this.deps.records(chatId)).get(x.pid);
|
|
2245
|
+
}
|
|
2246
|
+
const p = folded.state === 'accepting' && folded.accepting !== undefined ? folded.accepting.resolution : folded.proposal;
|
|
2247
|
+
if (folded.state === 'accepting' && folded.accepting !== undefined) {
|
|
2248
|
+
// A retry after the replacement launched (a lost response, a crash before the decision): adopt it (codex r1).
|
|
2249
|
+
const found = await this.deps.registry.find('job', folded.accepting.identity);
|
|
2250
|
+
if (found !== null) {
|
|
2251
|
+
const result = { runId: folded.accepting.identity.runId, artifactRef: null, adopted: true, stub: found.stub };
|
|
2252
|
+
if (!this.decided(chatId, folded.turnId, x.pid, actor, 'go', result, folded.accepting.resolution, folded.accepting.edits, instance))
|
|
2253
|
+
return this.gone(chatId);
|
|
2254
|
+
return { code: 200, body: { view: viewOf(foldProposals(this.deps.records(chatId)).get(x.pid)) } };
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
// Only the open (or interrupted) newest proposal of its lineage goes on: checked before any Reject (codex r3).
|
|
2258
|
+
if (folded.state === 'superseded' || folded.state === 'revising') {
|
|
2259
|
+
return { code: 409, body: { code: folded.state === 'revising' ? 'proposal_revising' : 'proposal_superseded', error: 'this reshape changed since; check it again', view: viewOf(folded) } };
|
|
2260
|
+
}
|
|
2261
|
+
const newest = [...foldProposals(this.deps.records(chatId)).values()].filter((f) => f.proposal.lineage === p.lineage).pop();
|
|
2262
|
+
if (newest !== undefined && newest.proposal.pid !== x.pid) {
|
|
2263
|
+
return { code: 409, body: { code: 'proposal_superseded', error: 'a newer version of this job replaced this reshape', view: viewOf(newest) } };
|
|
2264
|
+
}
|
|
2265
|
+
// A retry is checked against the catalog like any Go, interrupted ones included (codex r2, r3).
|
|
2266
|
+
const stale = await this.jobStale(chatId, folded, instance);
|
|
2267
|
+
if (stale !== null)
|
|
2268
|
+
return stale;
|
|
2269
|
+
if (folded.state !== 'accepting') {
|
|
2270
|
+
if (p.blocked !== null)
|
|
2271
|
+
return { code: 409, body: { code: 'proposal_blocked', error: p.blocked, view: viewOf(folded) } };
|
|
2272
|
+
}
|
|
2273
|
+
const current = folded.state === 'accepting' && folded.accepting !== undefined ? folded.accepting.resolution : folded.proposal;
|
|
2274
|
+
const identity = folded.accepting?.identity ?? this.identityOf(current);
|
|
2275
|
+
return this.goLocked(chatId, folded, current, null, identity, actor, instance);
|
|
2276
|
+
}));
|
|
2277
|
+
}
|
|
2278
|
+
/** A proposal of this chat, folded, or `null`. */
|
|
2279
|
+
viewOfPid(chatId, pid) {
|
|
2280
|
+
const f = foldProposals(this.deps.records(chatId)).get(pid);
|
|
2281
|
+
return f === undefined ? null : viewOf(f);
|
|
2282
|
+
}
|
|
2283
|
+
/** The proposal as it was accepted (its effective resolution), else as it stands; `null` when the chat has none. */
|
|
2284
|
+
proposalOfPid(chatId, pid) {
|
|
2285
|
+
const f = foldProposals(this.deps.records(chatId)).get(pid);
|
|
2286
|
+
return f === undefined ? null : (f.accepting?.resolution ?? f.proposal);
|
|
2287
|
+
}
|
|
1470
2288
|
// ── A3: what the create launcher and the daemon need from the proposals ────────────────────────────────────────────
|
|
1471
2289
|
/**
|
|
1472
2290
|
* The accepted proposal a create's `chat_id` + `proposal_id` names, for this actor (§5.2): accepting (or decided go),
|