wicked-crew 0.17.1 → 0.18.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 +49 -14
- package/adapters/web-source.lock +1314 -0
- package/dist/api/audit.d.ts +5 -0
- package/dist/api/audit.d.ts.map +1 -1
- package/dist/api/audit.js +20 -0
- package/dist/api/audit.js.map +1 -1
- package/dist/api/auth.d.ts.map +1 -1
- package/dist/api/auth.js +3 -0
- package/dist/api/auth.js.map +1 -1
- package/dist/api/chat-context.js +1 -1
- package/dist/api/chat-history.d.ts +3 -0
- package/dist/api/chat-history.d.ts.map +1 -1
- package/dist/api/chat-history.js +6 -1
- package/dist/api/chat-history.js.map +1 -1
- package/dist/api/chat-jobs.d.ts +30 -1
- package/dist/api/chat-jobs.d.ts.map +1 -1
- package/dist/api/chat-jobs.js +172 -10
- package/dist/api/chat-jobs.js.map +1 -1
- package/dist/api/chat-proposals.d.ts +178 -8
- package/dist/api/chat-proposals.d.ts.map +1 -1
- package/dist/api/chat-proposals.js +775 -54
- package/dist/api/chat-proposals.js.map +1 -1
- package/dist/api/chat-requirements.d.ts +54 -0
- package/dist/api/chat-requirements.d.ts.map +1 -0
- package/dist/api/chat-requirements.js +282 -0
- package/dist/api/chat-requirements.js.map +1 -0
- package/dist/api/chat-scope.d.ts +56 -0
- package/dist/api/chat-scope.d.ts.map +1 -1
- package/dist/api/chat-scope.js +175 -5
- package/dist/api/chat-scope.js.map +1 -1
- package/dist/api/chat-transcripts.d.ts +7 -0
- package/dist/api/chat-transcripts.d.ts.map +1 -1
- package/dist/api/chat-transcripts.js +17 -1
- package/dist/api/chat-transcripts.js.map +1 -1
- package/dist/api/delivery-index.d.ts +109 -5
- package/dist/api/delivery-index.d.ts.map +1 -1
- package/dist/api/delivery-index.js +199 -7
- package/dist/api/delivery-index.js.map +1 -1
- package/dist/api/mcp.d.ts +7 -2
- package/dist/api/mcp.d.ts.map +1 -1
- package/dist/api/mcp.js +1 -1
- package/dist/api/mcp.js.map +1 -1
- package/dist/api/needs.d.ts.map +1 -1
- package/dist/api/needs.js +19 -1
- package/dist/api/needs.js.map +1 -1
- package/dist/api/product.d.ts +9 -2
- package/dist/api/product.d.ts.map +1 -1
- package/dist/api/product.js +10 -2
- package/dist/api/product.js.map +1 -1
- package/dist/api/proposal-theme.d.ts +23 -0
- package/dist/api/proposal-theme.d.ts.map +1 -0
- package/dist/api/proposal-theme.js +30 -0
- package/dist/api/proposal-theme.js.map +1 -0
- package/dist/api/recording.d.ts +70 -10
- package/dist/api/recording.d.ts.map +1 -1
- package/dist/api/recording.js +278 -39
- package/dist/api/recording.js.map +1 -1
- package/dist/api/repo-input.d.ts +55 -0
- package/dist/api/repo-input.d.ts.map +1 -0
- package/dist/api/repo-input.js +113 -0
- package/dist/api/repo-input.js.map +1 -0
- package/dist/api/requirements.d.ts +75 -0
- package/dist/api/requirements.d.ts.map +1 -1
- package/dist/api/requirements.js +97 -9
- package/dist/api/requirements.js.map +1 -1
- package/dist/api/review-change.d.ts +64 -0
- package/dist/api/review-change.d.ts.map +1 -0
- package/dist/api/review-change.js +214 -0
- package/dist/api/review-change.js.map +1 -0
- package/dist/api/roster-standing.d.ts +4 -0
- package/dist/api/roster-standing.d.ts.map +1 -1
- package/dist/api/roster-standing.js +43 -10
- package/dist/api/roster-standing.js.map +1 -1
- package/dist/api/routes.d.ts +63 -6
- package/dist/api/routes.d.ts.map +1 -1
- package/dist/api/routes.js +818 -269
- package/dist/api/routes.js.map +1 -1
- package/dist/api/run-documents.d.ts +97 -0
- package/dist/api/run-documents.d.ts.map +1 -0
- package/dist/api/run-documents.js +458 -0
- package/dist/api/run-documents.js.map +1 -0
- package/dist/api/run-sources.d.ts +51 -0
- package/dist/api/run-sources.d.ts.map +1 -0
- package/dist/api/run-sources.js +133 -0
- package/dist/api/run-sources.js.map +1 -0
- package/dist/api/runtime-state.d.ts +41 -0
- package/dist/api/runtime-state.d.ts.map +1 -0
- package/dist/api/runtime-state.js +75 -0
- package/dist/api/runtime-state.js.map +1 -0
- package/dist/api/seat-container-login.d.ts +51 -0
- package/dist/api/seat-container-login.d.ts.map +1 -1
- package/dist/api/seat-container-login.js +317 -1
- package/dist/api/seat-container-login.js.map +1 -1
- package/dist/api/seat-images.d.ts.map +1 -1
- package/dist/api/seat-images.js +7 -0
- package/dist/api/seat-images.js.map +1 -1
- package/dist/api/server.d.ts +7 -0
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +206 -25
- package/dist/api/server.js.map +1 -1
- package/dist/api/skills.d.ts +8 -0
- package/dist/api/skills.d.ts.map +1 -1
- package/dist/api/skills.js +21 -0
- package/dist/api/skills.js.map +1 -1
- package/dist/api/system-snapshot.d.ts +7 -2
- package/dist/api/system-snapshot.d.ts.map +1 -1
- package/dist/api/system-snapshot.js +31 -7
- package/dist/api/system-snapshot.js.map +1 -1
- package/dist/api/testing.d.ts +3 -3
- package/dist/api/ui-text.d.ts +45 -0
- package/dist/api/ui-text.d.ts.map +1 -0
- package/dist/api/ui-text.js +188 -0
- package/dist/api/ui-text.js.map +1 -0
- package/dist/apps/actions/card.d.ts +62 -0
- package/dist/apps/actions/card.d.ts.map +1 -0
- package/dist/apps/actions/card.js +111 -0
- package/dist/apps/actions/card.js.map +1 -0
- package/dist/apps/actions/write-path.d.ts.map +1 -1
- package/dist/apps/actions/write-path.js +26 -77
- package/dist/apps/actions/write-path.js.map +1 -1
- package/dist/apps/exec/sources.d.ts.map +1 -1
- package/dist/apps/exec/sources.js +3 -0
- package/dist/apps/exec/sources.js.map +1 -1
- package/dist/apps/publish/artifacts.d.ts +18 -0
- package/dist/apps/publish/artifacts.d.ts.map +1 -0
- package/dist/apps/publish/artifacts.js +87 -0
- package/dist/apps/publish/artifacts.js.map +1 -0
- package/dist/apps/publish/check.d.ts +103 -0
- package/dist/apps/publish/check.d.ts.map +1 -0
- package/dist/apps/publish/check.js +235 -0
- package/dist/apps/publish/check.js.map +1 -0
- package/dist/apps/publish/image.d.ts +2 -0
- package/dist/apps/publish/image.d.ts.map +1 -1
- package/dist/apps/publish/image.js +2 -1
- package/dist/apps/publish/image.js.map +1 -1
- package/dist/apps/publish/render.d.ts +71 -0
- package/dist/apps/publish/render.d.ts.map +1 -0
- package/dist/apps/publish/render.js +122 -0
- package/dist/apps/publish/render.js.map +1 -0
- package/dist/apps/publish/run.d.ts +35 -0
- package/dist/apps/publish/run.d.ts.map +1 -0
- package/dist/apps/publish/run.js +127 -0
- package/dist/apps/publish/run.js.map +1 -0
- package/dist/apps/routes.d.ts +54 -2
- package/dist/apps/routes.d.ts.map +1 -1
- package/dist/apps/routes.js +124 -7
- package/dist/apps/routes.js.map +1 -1
- package/dist/apps/spec.d.ts +8 -8
- package/dist/apps/store.d.ts +84 -5
- package/dist/apps/store.d.ts.map +1 -1
- package/dist/apps/store.js +191 -4
- package/dist/apps/store.js.map +1 -1
- package/dist/apps/turns.d.ts +19 -1
- package/dist/apps/turns.d.ts.map +1 -1
- package/dist/apps/turns.js +60 -2
- package/dist/apps/turns.js.map +1 -1
- package/dist/apps/views.d.ts +5 -1
- package/dist/apps/views.d.ts.map +1 -1
- package/dist/apps/views.js +18 -7
- package/dist/apps/views.js.map +1 -1
- package/dist/apps-server/Dockerfile +25 -0
- package/dist/apps-server/runners/sqlite-runner.mjs +110 -0
- package/dist/apps-server/server/lib/bundle/server.mjs +92523 -0
- package/dist/apps-server/server/node_modules/@pgsql/types/LICENSE +22 -0
- package/dist/apps-server/server/node_modules/@pgsql/types/README.md +106 -0
- package/dist/apps-server/server/node_modules/@pgsql/types/enums.d.ts +76 -0
- package/dist/apps-server/server/node_modules/@pgsql/types/enums.js +2 -0
- package/dist/apps-server/server/node_modules/@pgsql/types/esm/enums.js +1 -0
- package/dist/apps-server/server/node_modules/@pgsql/types/esm/index.js +2 -0
- package/dist/apps-server/server/node_modules/@pgsql/types/esm/types.js +1 -0
- package/dist/apps-server/server/node_modules/@pgsql/types/index.d.ts +2 -0
- package/dist/apps-server/server/node_modules/@pgsql/types/index.js +18 -0
- package/dist/apps-server/server/node_modules/@pgsql/types/package.json +36 -0
- package/dist/apps-server/server/node_modules/@pgsql/types/types.d.ts +2488 -0
- package/dist/apps-server/server/node_modules/@pgsql/types/types.js +2 -0
- package/dist/apps-server/server/node_modules/libpg-query/LICENSE +22 -0
- package/dist/apps-server/server/node_modules/libpg-query/README.md +275 -0
- package/dist/apps-server/server/node_modules/libpg-query/package.json +58 -0
- package/dist/apps-server/server/node_modules/libpg-query/wasm/index.cjs +369 -0
- package/dist/apps-server/server/node_modules/libpg-query/wasm/index.d.ts +48 -0
- package/dist/apps-server/server/node_modules/libpg-query/wasm/index.js +344 -0
- package/dist/apps-server/server/node_modules/libpg-query/wasm/libpg-query.js +2 -0
- package/dist/apps-server/server/node_modules/libpg-query/wasm/libpg-query.wasm +0 -0
- package/dist/apps-server/server/shim/host.css +22 -0
- package/dist/apps-server/server/shim/host.js +1 -0
- package/dist/cli/apps-check.d.ts +18 -0
- package/dist/cli/apps-check.d.ts.map +1 -1
- package/dist/cli/apps-check.js +179 -5
- package/dist/cli/apps-check.js.map +1 -1
- package/dist/cli/apps-produce.d.ts +9 -0
- package/dist/cli/apps-produce.d.ts.map +1 -0
- package/dist/cli/apps-produce.js +27 -0
- package/dist/cli/apps-produce.js.map +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +15 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/insights-facts.d.ts +17 -0
- package/dist/cli/insights-facts.d.ts.map +1 -0
- package/dist/cli/insights-facts.js +56 -0
- package/dist/cli/insights-facts.js.map +1 -0
- package/dist/core/adapter.d.ts +74 -15
- package/dist/core/adapter.d.ts.map +1 -1
- package/dist/core/adapter.js +245 -53
- package/dist/core/adapter.js.map +1 -1
- package/dist/core/engine-roster.d.ts.map +1 -1
- package/dist/core/engine-roster.js +1 -0
- package/dist/core/engine-roster.js.map +1 -1
- package/dist/core/estate-mcp-client.d.ts +3 -2
- package/dist/core/estate-mcp-client.d.ts.map +1 -1
- package/dist/core/estate-mcp-client.js +3 -2
- package/dist/core/estate-mcp-client.js.map +1 -1
- package/dist/core/run-identity.d.ts.map +1 -1
- package/dist/core/run-identity.js +3 -0
- package/dist/core/run-identity.js.map +1 -1
- package/dist/core/types.d.ts +5 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/editors/conformance-runtime.d.ts +107 -0
- package/dist/editors/conformance-runtime.d.ts.map +1 -1
- package/dist/editors/conformance-runtime.js +268 -13
- package/dist/editors/conformance-runtime.js.map +1 -1
- package/dist/editors/csp.d.ts +2 -2
- package/dist/editors/csp.d.ts.map +1 -1
- package/dist/editors/csp.js +4 -2
- package/dist/editors/csp.js.map +1 -1
- package/dist/editors/pack-install.d.ts +28 -13
- package/dist/editors/pack-install.d.ts.map +1 -1
- package/dist/editors/pack-install.js +96 -48
- package/dist/editors/pack-install.js.map +1 -1
- package/dist/editors/registry.d.ts +111 -8
- package/dist/editors/registry.d.ts.map +1 -1
- package/dist/editors/registry.js +183 -7
- package/dist/editors/registry.js.map +1 -1
- package/dist/editors/routes.d.ts +66 -13
- package/dist/editors/routes.d.ts.map +1 -1
- package/dist/editors/routes.js +277 -44
- package/dist/editors/routes.js.map +1 -1
- package/dist/evals/replay.d.ts +6 -0
- package/dist/evals/replay.d.ts.map +1 -1
- package/dist/evals/replay.js +24 -1
- package/dist/evals/replay.js.map +1 -1
- package/dist/evals/routes.d.ts.map +1 -1
- package/dist/evals/routes.js +17 -2
- package/dist/evals/routes.js.map +1 -1
- package/dist/evals/runner.d.ts.map +1 -1
- package/dist/evals/runner.js +5 -0
- package/dist/evals/runner.js.map +1 -1
- package/dist/evals/shape-corrections.d.ts +146 -0
- package/dist/evals/shape-corrections.d.ts.map +1 -0
- package/dist/evals/shape-corrections.js +394 -0
- package/dist/evals/shape-corrections.js.map +1 -0
- package/dist/evals/shape.d.ts +145 -0
- package/dist/evals/shape.d.ts.map +1 -0
- package/dist/evals/shape.js +376 -0
- package/dist/evals/shape.js.map +1 -0
- package/dist/evals/types.d.ts +2 -2
- package/dist/evals/types.d.ts.map +1 -1
- package/dist/evals/types.js +2 -1
- package/dist/evals/types.js.map +1 -1
- package/dist/insights/analyze.d.ts +14 -1
- package/dist/insights/analyze.d.ts.map +1 -1
- package/dist/insights/analyze.js +35 -8
- package/dist/insights/analyze.js.map +1 -1
- package/dist/insights/cost.d.ts +123 -0
- package/dist/insights/cost.d.ts.map +1 -0
- package/dist/insights/cost.js +221 -0
- package/dist/insights/cost.js.map +1 -0
- package/dist/insights/review-service.d.ts +20 -1
- package/dist/insights/review-service.d.ts.map +1 -1
- package/dist/insights/review-service.js +50 -25
- package/dist/insights/review-service.js.map +1 -1
- package/dist/insights/routes.d.ts +29 -0
- package/dist/insights/routes.d.ts.map +1 -1
- package/dist/insights/routes.js +62 -0
- package/dist/insights/routes.js.map +1 -1
- package/dist/insights/run-facts.d.ts +16 -0
- package/dist/insights/run-facts.d.ts.map +1 -1
- package/dist/insights/run-facts.js +26 -3
- package/dist/insights/run-facts.js.map +1 -1
- package/dist/interactive/bridge-pool.d.ts +11 -2
- package/dist/interactive/bridge-pool.d.ts.map +1 -1
- package/dist/interactive/bridge-pool.js +10 -1
- package/dist/interactive/bridge-pool.js.map +1 -1
- package/dist/interactive/chat-events.d.ts +74 -1
- package/dist/interactive/chat-events.d.ts.map +1 -1
- package/dist/interactive/chat-events.js +338 -6
- package/dist/interactive/chat-events.js.map +1 -1
- package/dist/interactive/doc-binding.d.ts +15 -0
- package/dist/interactive/doc-binding.d.ts.map +1 -1
- package/dist/interactive/doc-binding.js +4 -0
- package/dist/interactive/doc-binding.js.map +1 -1
- package/dist/interactive/doc-checks-routes.d.ts +34 -1
- package/dist/interactive/doc-checks-routes.d.ts.map +1 -1
- package/dist/interactive/doc-checks-routes.js +84 -0
- package/dist/interactive/doc-checks-routes.js.map +1 -1
- package/dist/interactive/draft-events.d.ts +7 -0
- package/dist/interactive/draft-events.d.ts.map +1 -1
- package/dist/interactive/draft-events.js +38 -6
- package/dist/interactive/draft-events.js.map +1 -1
- package/dist/interactive/draft-skill.d.ts +76 -6
- package/dist/interactive/draft-skill.d.ts.map +1 -1
- package/dist/interactive/draft-skill.js +219 -17
- package/dist/interactive/draft-skill.js.map +1 -1
- package/dist/interactive/edit-events.d.ts.map +1 -1
- package/dist/interactive/edit-events.js +4 -2
- package/dist/interactive/edit-events.js.map +1 -1
- package/dist/interactive/landing-guard.d.ts +47 -0
- package/dist/interactive/landing-guard.d.ts.map +1 -0
- package/dist/interactive/landing-guard.js +43 -0
- package/dist/interactive/landing-guard.js.map +1 -0
- package/dist/interactive/landing-record.d.ts +68 -0
- package/dist/interactive/landing-record.d.ts.map +1 -0
- package/dist/interactive/landing-record.js +154 -0
- package/dist/interactive/landing-record.js.map +1 -0
- package/dist/interactive/proposal-create.d.ts +3 -1
- package/dist/interactive/proposal-create.d.ts.map +1 -1
- package/dist/interactive/proposal-create.js +14 -2
- package/dist/interactive/proposal-create.js.map +1 -1
- package/dist/interactive/proposal-refine.d.ts +48 -0
- package/dist/interactive/proposal-refine.d.ts.map +1 -0
- package/dist/interactive/proposal-refine.js +99 -0
- package/dist/interactive/proposal-refine.js.map +1 -0
- package/dist/interactive/protected-edits.d.ts +67 -0
- package/dist/interactive/protected-edits.d.ts.map +1 -0
- package/dist/interactive/protected-edits.js +160 -0
- package/dist/interactive/protected-edits.js.map +1 -0
- package/dist/interactive/proxy-routes.js +2 -2
- package/dist/interactive/review-events.js +1 -1
- package/dist/interactive/run-units.d.ts +1 -1
- package/dist/interactive/run-units.d.ts.map +1 -1
- package/dist/interactive/run-units.js +8 -2
- package/dist/interactive/run-units.js.map +1 -1
- package/dist/interactive/source-packet.d.ts +66 -1
- package/dist/interactive/source-packet.d.ts.map +1 -1
- package/dist/interactive/source-packet.js +309 -60
- package/dist/interactive/source-packet.js.map +1 -1
- package/dist/interactive/theme-events.js +1 -1
- package/dist/knowledge/adapters/web/egress.d.ts +99 -0
- package/dist/knowledge/adapters/web/egress.d.ts.map +1 -0
- package/dist/knowledge/adapters/web/egress.js +330 -0
- package/dist/knowledge/adapters/web/egress.js.map +1 -0
- package/dist/knowledge/adapters/web/engine.d.ts +54 -0
- package/dist/knowledge/adapters/web/engine.d.ts.map +1 -0
- package/dist/knowledge/adapters/web/engine.js +101 -0
- package/dist/knowledge/adapters/web/engine.js.map +1 -0
- package/dist/knowledge/adapters/web/fetch.d.ts +131 -0
- package/dist/knowledge/adapters/web/fetch.d.ts.map +1 -0
- package/dist/knowledge/adapters/web/fetch.js +325 -0
- package/dist/knowledge/adapters/web/fetch.js.map +1 -0
- package/dist/knowledge/adapters/web/gate-web.d.ts +182 -0
- package/dist/knowledge/adapters/web/gate-web.d.ts.map +1 -0
- package/dist/knowledge/adapters/web/gate-web.js +496 -0
- package/dist/knowledge/adapters/web/gate-web.js.map +1 -0
- package/dist/knowledge/adapters/web/routes.d.ts +36 -0
- package/dist/knowledge/adapters/web/routes.d.ts.map +1 -0
- package/dist/knowledge/adapters/web/routes.js +99 -0
- package/dist/knowledge/adapters/web/routes.js.map +1 -0
- package/dist/knowledge/adapters/web/searxng.d.ts +89 -0
- package/dist/knowledge/adapters/web/searxng.d.ts.map +1 -0
- package/dist/knowledge/adapters/web/searxng.js +274 -0
- package/dist/knowledge/adapters/web/searxng.js.map +1 -0
- package/dist/knowledge/adapters/web/source.d.ts +65 -0
- package/dist/knowledge/adapters/web/source.d.ts.map +1 -0
- package/dist/knowledge/adapters/web/source.js +192 -0
- package/dist/knowledge/adapters/web/source.js.map +1 -0
- package/dist/knowledge/gate/gate.d.ts +22 -0
- package/dist/knowledge/gate/gate.d.ts.map +1 -1
- package/dist/knowledge/gate/gate.js +62 -1
- package/dist/knowledge/gate/gate.js.map +1 -1
- package/dist/knowledge/gate/sources.d.ts +2 -0
- package/dist/knowledge/gate/sources.d.ts.map +1 -1
- package/dist/knowledge/gate/sources.js +5 -2
- package/dist/knowledge/gate/sources.js.map +1 -1
- package/dist/knowledge/package.d.ts +7 -0
- package/dist/knowledge/package.d.ts.map +1 -1
- package/dist/knowledge/package.js +15 -1
- package/dist/knowledge/package.js.map +1 -1
- package/dist/knowledge/trackers/actions.js +1 -1
- package/dist/knowledge/trackers/actions.js.map +1 -1
- package/dist/knowledge/trackers/bindings.d.ts +3 -3
- package/dist/knowledge/trackers/bindings.d.ts.map +1 -1
- package/dist/knowledge/trackers/bindings.js +36 -23
- package/dist/knowledge/trackers/bindings.js.map +1 -1
- package/dist/knowledge/trackers/routes.js +1 -1
- package/dist/knowledge/trackers/routes.js.map +1 -1
- package/dist/learnings/service.d.ts.map +1 -1
- package/dist/learnings/service.js +2 -0
- package/dist/learnings/service.js.map +1 -1
- package/dist/mcp/broker.d.ts +8 -0
- package/dist/mcp/broker.d.ts.map +1 -1
- package/dist/mcp/broker.js +48 -3
- package/dist/mcp/broker.js.map +1 -1
- package/dist/mcp/estate-relay.d.ts +43 -1
- package/dist/mcp/estate-relay.d.ts.map +1 -1
- package/dist/mcp/estate-relay.js +38 -2
- package/dist/mcp/estate-relay.js.map +1 -1
- package/dist/mcp/registry.d.ts +6 -0
- package/dist/mcp/registry.d.ts.map +1 -1
- package/dist/mcp/registry.js +42 -3
- package/dist/mcp/registry.js.map +1 -1
- package/dist/mcp/run-fence.d.ts +57 -0
- package/dist/mcp/run-fence.d.ts.map +1 -0
- package/dist/mcp/run-fence.js +86 -0
- package/dist/mcp/run-fence.js.map +1 -0
- package/dist/mcp/tool-list.d.ts +5 -0
- package/dist/mcp/tool-list.d.ts.map +1 -1
- package/dist/mcp/tool-list.js +7 -3
- package/dist/mcp/tool-list.js.map +1 -1
- package/dist/presets/routes.d.ts.map +1 -1
- package/dist/presets/routes.js +6 -0
- package/dist/presets/routes.js.map +1 -1
- package/dist/projects/routes.d.ts +1 -1
- package/dist/projects/state-home-preflight.d.ts.map +1 -1
- package/dist/projects/state-home-preflight.js +2 -0
- package/dist/projects/state-home-preflight.js.map +1 -1
- package/dist/setup/tool-path.d.ts +16 -0
- package/dist/setup/tool-path.d.ts.map +1 -0
- package/dist/setup/tool-path.js +66 -0
- package/dist/setup/tool-path.js.map +1 -0
- package/dist/skills/plugin-source.d.ts +46 -88
- package/dist/skills/plugin-source.d.ts.map +1 -1
- package/dist/skills/plugin-source.js +144 -100
- package/dist/skills/plugin-source.js.map +1 -1
- package/dist/skills/runtime.d.ts +47 -0
- package/dist/skills/runtime.d.ts.map +1 -1
- package/dist/skills/runtime.js +110 -14
- package/dist/skills/runtime.js.map +1 -1
- package/dist/skills/store.d.ts +2 -0
- package/dist/skills/store.d.ts.map +1 -1
- package/dist/skills/store.js +29 -14
- package/dist/skills/store.js.map +1 -1
- package/dist/skills/usage.d.ts +238 -0
- package/dist/skills/usage.d.ts.map +1 -0
- package/dist/skills/usage.js +789 -0
- package/dist/skills/usage.js.map +1 -0
- package/dist/skills/venv.d.ts +18 -2
- package/dist/skills/venv.d.ts.map +1 -1
- package/dist/skills/venv.js +2 -2
- package/dist/skills/venv.js.map +1 -1
- package/dist/sources/routes.d.ts +3 -1
- package/dist/sources/routes.d.ts.map +1 -1
- package/dist/sources/routes.js +11 -0
- package/dist/sources/routes.js.map +1 -1
- package/dist/standing-orders/parse.d.ts +19 -0
- package/dist/standing-orders/parse.d.ts.map +1 -1
- package/dist/standing-orders/parse.js +61 -18
- package/dist/standing-orders/parse.js.map +1 -1
- package/dist/studio/apps-standalone/fixture.html +12 -0
- package/dist/studio/apps-standalone/fixture.js +10 -0
- package/dist/studio/apps-standalone/runtime.css +139 -0
- package/dist/studio/apps-standalone/runtime.js +1 -0
- package/dist/studio/assets/{KnowledgeGraph-Cpm46tEp.js → KnowledgeGraph-BT5Y-B8b.js} +1 -1
- package/dist/studio/assets/index-B_JwrHVF.css +32 -0
- package/dist/studio/assets/index-Bl9m8ldl.js +1104 -0
- package/dist/studio/editors/wicked-apps/editor.json +1 -1
- package/dist/studio/editors/wicked-apps/index.html +2 -2
- package/dist/studio/editors/wicked-deck/editor.json +1 -1
- package/dist/studio/editors/wicked-deck/index.html +14 -1
- package/dist/studio/editors/wicked-doc/editor.json +1 -1
- package/dist/studio/editors/wicked-doc/index.html +1 -1
- 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 +10 -1
- package/dist/studio/editors/wicked-page/index.html +2 -2
- package/dist/studio/editors/wicked-video/editor.json +7 -2
- package/dist/studio/editors/wicked-video/index.html +14 -11
- package/dist/studio/index.html +2 -2
- package/dist/studio/testid-inventory.json +2073 -240
- package/dist/team/routes.d.ts +1 -1
- package/dist/workflow-catalog/build-v2.d.ts +6 -2
- package/dist/workflow-catalog/build-v2.d.ts.map +1 -1
- package/dist/workflow-catalog/build-v2.js +37 -13
- package/dist/workflow-catalog/build-v2.js.map +1 -1
- package/dist/workflow-catalog/catalog-data-v2.d.ts.map +1 -1
- package/dist/workflow-catalog/catalog-data-v2.js +310 -105
- package/dist/workflow-catalog/catalog-data-v2.js.map +1 -1
- package/dist/workflow-catalog/catalog-data.d.ts.map +1 -1
- package/dist/workflow-catalog/catalog-data.js +2 -20
- package/dist/workflow-catalog/catalog-data.js.map +1 -1
- package/dist/workflow-catalog/detect-service.d.ts +95 -0
- package/dist/workflow-catalog/detect-service.d.ts.map +1 -0
- package/dist/workflow-catalog/detect-service.js +239 -0
- package/dist/workflow-catalog/detect-service.js.map +1 -0
- package/dist/workflow-catalog/detect.d.ts +213 -0
- package/dist/workflow-catalog/detect.d.ts.map +1 -0
- package/dist/workflow-catalog/detect.js +653 -0
- package/dist/workflow-catalog/detect.js.map +1 -0
- package/dist/workflow-catalog/shape.d.ts +3 -1
- package/dist/workflow-catalog/shape.d.ts.map +1 -1
- package/dist/workflow-catalog/shape.js +7 -1
- package/dist/workflow-catalog/shape.js.map +1 -1
- package/dist/working-doc/bridge-backend.js +2 -2
- package/dist/working-doc/event-lines.d.ts +67 -2
- package/dist/working-doc/event-lines.d.ts.map +1 -1
- package/dist/working-doc/event-lines.js +155 -8
- package/dist/working-doc/event-lines.js.map +1 -1
- package/dist/working-doc/notes-index.d.ts +35 -0
- package/dist/working-doc/notes-index.d.ts.map +1 -0
- package/dist/working-doc/notes-index.js +82 -0
- package/dist/working-doc/notes-index.js.map +1 -0
- package/dist/working-doc/routes.js +4 -4
- package/dist/working-doc/sections.js +2 -2
- package/dist/working-doc/service.d.ts +260 -21
- package/dist/working-doc/service.d.ts.map +1 -1
- package/dist/working-doc/service.js +791 -90
- package/dist/working-doc/service.js.map +1 -1
- package/dist/working-doc/store.d.ts +50 -1
- package/dist/working-doc/store.d.ts.map +1 -1
- package/dist/working-doc/store.js +4 -1
- package/dist/working-doc/store.js.map +1 -1
- package/endpoint-manifest.json +187 -3
- package/evals/corpora/shape-corrections-v1.json +594 -0
- package/evals/corpora/shape-corrections-v1.seat-fixture.json +186 -0
- package/evals/corpora/shape-v1.json +2113 -0
- package/evals/corpora/shape-v1.seat-fixture.json +1800 -0
- package/package.json +11 -7
- package/scripts/apps-render.py +226 -0
- package/workflows/detect-shape.json +29 -0
- package/dist/studio/assets/index-BRBwWQMH.css +0 -32
- package/dist/studio/assets/index-CVrWDGRP.js +0 -1097
|
@@ -39,9 +39,13 @@ import { dirname } from 'node:path';
|
|
|
39
39
|
import { z } from '../zod.js';
|
|
40
40
|
import { parseCommand, resolveOption } from '../workflow-catalog/build-v2.js';
|
|
41
41
|
import { CATALOG_V2_CARDS } from '../workflow-catalog/catalog-data-v2.js';
|
|
42
|
-
import {
|
|
42
|
+
import { REVIEW_CHANGE_WORKFLOW } from './review-change.js';
|
|
43
|
+
import { checksLabel, ownWords, factsOf, JobRefusal, mergeRevision, nounOf, optionFor, personAskedSkip, personPid, proposalKindOf, qeSkipBound, requestDigest, repoOf, resolveJob, SEAT_WORDS, seatProtections, briefOf, inputLines, SELF_SEATED, } from './chat-jobs.js';
|
|
43
44
|
import { artifactExists, artifactHead, chatMount, parseArtifactRef, UNFILED_MOUNT } from './chat-context.js';
|
|
45
|
+
import { ATTACHMENT_MAX_FILE_BYTES } from './chat-attachments.js';
|
|
46
|
+
import { documentPathPlan } from '../interactive/source-packet.js';
|
|
44
47
|
import { tornTailPrefix } from './chat-transcripts.js';
|
|
48
|
+
import { catalogDigest, detect, detectable } from '../workflow-catalog/detect.js';
|
|
45
49
|
// ── the block ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
46
50
|
/** Sources a block may name. */
|
|
47
51
|
export const PROPOSAL_SOURCES_MAX = 12;
|
|
@@ -61,6 +65,11 @@ export const ThemePatchSchema = z.strictObject({
|
|
|
61
65
|
.refine((p) => Object.keys(p).length > 0, 'a theme patch changes at least one key');
|
|
62
66
|
const EntryBlock = z.object({
|
|
63
67
|
entry: z.string().trim().min(1).max(80),
|
|
68
|
+
// DES-CATALOG-002 §2.3: a job routing block names the card's option, an Investigate card's depth, and how sure the
|
|
69
|
+
// seat is (garden classify's catalog mode). Validated, cross-checked and banded by crew (`workflow-catalog/detect.ts`).
|
|
70
|
+
option: z.string().trim().max(80).nullable().optional(),
|
|
71
|
+
depth: z.enum(['quick', 'standard', 'deep']).nullable().optional(),
|
|
72
|
+
confidence: z.number().optional(),
|
|
64
73
|
title: z.string().trim().max(200).optional(),
|
|
65
74
|
brief: z.string().max(8000).optional(),
|
|
66
75
|
url: z.string().trim().max(2048).optional(),
|
|
@@ -111,6 +120,8 @@ const InputValueSchema = z.discriminatedUnion('kind', [
|
|
|
111
120
|
z.strictObject({ kind: z.literal('text'), value: z.string().max(8000) }),
|
|
112
121
|
z.strictObject({ kind: z.literal('url'), value: z.string().max(2048) }),
|
|
113
122
|
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) }),
|
|
123
|
+
z.strictObject({ kind: z.literal('documents'), tokens: z.array(z.string().min(1).max(300)).min(1).max(20) }),
|
|
124
|
+
z.strictObject({ kind: z.literal('sources'), ids: z.array(z.string().min(1).max(100)).max(20) }),
|
|
114
125
|
]);
|
|
115
126
|
/** (DES-CATALOG-002 §4.6) The edits of a {@link ProposalRevision}, as a block or a request carries them. Unknown keys
|
|
116
127
|
* pass through to the merge, which drops each with a note (a refused edit leaves the rest standing). */
|
|
@@ -148,6 +159,28 @@ export function parseRevisionBlock(body) {
|
|
|
148
159
|
return null;
|
|
149
160
|
return { revises: o['revises'], edits: edits.data };
|
|
150
161
|
}
|
|
162
|
+
/** (DES-CATALOG-002 §2.4) A seat's plan-edit block at a held plan: `{"planEdit":"<run id>"}`. `null` for anything else. */
|
|
163
|
+
export function parsePlanEditBlock(body) {
|
|
164
|
+
try {
|
|
165
|
+
const o = JSON.parse(body);
|
|
166
|
+
if (o === null || typeof o !== 'object' || Array.isArray(o))
|
|
167
|
+
return null;
|
|
168
|
+
const v = o['planEdit'];
|
|
169
|
+
return typeof v === 'string' && v.trim() !== '' && v.length <= 128 ? v.trim() : null;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** (DES-CATALOG-002 §2.3) The FIRST block of a reply that parses: one request yields at most one actionable card. */
|
|
176
|
+
export function firstValidBlock(bodies) {
|
|
177
|
+
for (const b of bodies) {
|
|
178
|
+
const parsed = parseMakeBlock(b);
|
|
179
|
+
if (parsed !== null)
|
|
180
|
+
return parsed;
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
151
184
|
/** The last block of a reply that parses (DES §4.1: the last valid block wins), or `null`. */
|
|
152
185
|
export function lastValidBlock(bodies) {
|
|
153
186
|
for (let i = bodies.length - 1; i >= 0; i -= 1) {
|
|
@@ -288,6 +321,10 @@ export class LaunchOnceRegistry {
|
|
|
288
321
|
register(kind, dispatcher) {
|
|
289
322
|
this.dispatchers.set(kind, dispatcher);
|
|
290
323
|
}
|
|
324
|
+
/** Share the registered create launcher's readers with its proposal's document plan. */
|
|
325
|
+
documentPacketDeps() {
|
|
326
|
+
return this.dispatchers.get('create')?.documentPacketDeps?.() ?? null;
|
|
327
|
+
}
|
|
291
328
|
has(kind) {
|
|
292
329
|
return this.dispatchers.has(kind);
|
|
293
330
|
}
|
|
@@ -519,6 +556,24 @@ function personWords(records, turnId) {
|
|
|
519
556
|
}
|
|
520
557
|
return out.join('\n');
|
|
521
558
|
}
|
|
559
|
+
/** (DES-CATALOG-002 §2.3) A proposal whose detection is still unsure (`ask`) holds no Start: its question is the guess's. */
|
|
560
|
+
export function withAskOverlay(p) {
|
|
561
|
+
const q = p.shape?.guess?.band === 'ask' ? p.shape.guess.question : null;
|
|
562
|
+
if (q === null || q === undefined)
|
|
563
|
+
return p;
|
|
564
|
+
return { ...p, blocked: q.text, question: null, suggestions: [], ...(p.sentence !== undefined ? { sentence: { ...p.sentence, ask: q.text } } : {}) };
|
|
565
|
+
}
|
|
566
|
+
/** (DES-CATALOG-002 §2.3) Whether an entry block routes a job card of the v2 catalog (its id is a detectable card's,
|
|
567
|
+
* or it carries the routing fields a job block has). */
|
|
568
|
+
export function isJobCardEntry(block) {
|
|
569
|
+
const card = CATALOG_V2_CARDS.find((c) => c.id === block.entry);
|
|
570
|
+
return (card !== undefined && detectable(card)) || block.option !== undefined || block.confidence !== undefined;
|
|
571
|
+
}
|
|
572
|
+
/** The person's own words of ONE turn (the message the seat's block answers). */
|
|
573
|
+
function turnWords(records, turnId) {
|
|
574
|
+
const r = records.find((x) => x.kind === 'user' && x.turnId === turnId && x.owner === true);
|
|
575
|
+
return r?.text ?? '';
|
|
576
|
+
}
|
|
522
577
|
/**
|
|
523
578
|
* Whether the person's own words name a document by its whole ref (`mount/doc`, or `doc:mount/doc`; studio's `default`
|
|
524
579
|
* mount alias for an Unfiled one): a longer name or path (`mount/doc-2`, `mount/doc_x`, `mount/doc/notes`,
|
|
@@ -556,6 +611,8 @@ function keepReshape(next, from) {
|
|
|
556
611
|
...(from.relaunch !== undefined ? { relaunch: from.relaunch } : {}),
|
|
557
612
|
...(from.reducedAssurance === true ? { reducedAssurance: true } : {}),
|
|
558
613
|
...(from.heldRejected === true ? { heldRejected: true } : {}),
|
|
614
|
+
// The plan version the reshape was offered on stays with every descendant (codex r2 on Lane D).
|
|
615
|
+
...(from.heldPlan !== undefined ? { heldPlan: from.heldPlan } : {}),
|
|
559
616
|
};
|
|
560
617
|
}
|
|
561
618
|
export class ChatProposals {
|
|
@@ -576,8 +633,11 @@ export class ChatProposals {
|
|
|
576
633
|
this.now = deps.now ?? Date.now;
|
|
577
634
|
this.log = deps.log ?? (() => undefined);
|
|
578
635
|
}
|
|
579
|
-
/** What a seat may be told it can make now (`chat-scope.ts`'s per-message digest).
|
|
580
|
-
|
|
636
|
+
/** What a seat may be told it can make now (`chat-scope.ts`'s per-message digest). With a chat id, how the chat routes
|
|
637
|
+
* new work too (DES-CATALOG-002 §2.3: job cards for a client that renders them, a command line for an older one).
|
|
638
|
+
* `o.appearance` (A7): whether the message carried the tab's appearance. A client that sends none cannot preview or
|
|
639
|
+
* apply a theme, so its seat is not told it can propose one (absent = not known here: the flag alone decides). */
|
|
640
|
+
digest(chatId, accepts, o = {}) {
|
|
581
641
|
const f = this.deps.flags();
|
|
582
642
|
const on = f.proposals;
|
|
583
643
|
const entries = on
|
|
@@ -592,12 +652,14 @@ export class ChatProposals {
|
|
|
592
652
|
})
|
|
593
653
|
: [];
|
|
594
654
|
// A create or demo with no catalog entry to name is not on (the seat is told nothing it could propose).
|
|
655
|
+
const jobs = chatId === undefined || !this.jobsOn() ? undefined : (accepts ?? this.acceptsJobs(chatId)) ? 'cards' : 'prose';
|
|
595
656
|
return {
|
|
596
657
|
create: on && f.create && entries.some((e) => e.kind === 'document'),
|
|
597
658
|
refine: on && f.refine,
|
|
598
|
-
theme: on && f.theme,
|
|
659
|
+
theme: on && f.theme && o.appearance !== false,
|
|
599
660
|
demo: on && f.demo && entries.some((e) => e.kind === 'demo'),
|
|
600
661
|
entries,
|
|
662
|
+
...(jobs !== undefined ? { jobs } : {}),
|
|
601
663
|
};
|
|
602
664
|
}
|
|
603
665
|
/** Resolutions still in flight (tests wait on them). */
|
|
@@ -610,13 +672,25 @@ export class ChatProposals {
|
|
|
610
672
|
* so it runs off the fold; the record is appended only if the chat is still the same instance.
|
|
611
673
|
*/
|
|
612
674
|
onReply(frame) {
|
|
675
|
+
// DES-CATALOG-002 §2.3: for a client that draws job cards, one request yields at most one actionable block: the
|
|
676
|
+
// FIRST valid one of any kind (a job, a revision, a plan edit, a refine, a theme), and only it is read (codex r1).
|
|
677
|
+
if (frame.blocks.length > 1 && this.jobsOn() && this.acceptsTurn(frame.chat, frame.turnId)) {
|
|
678
|
+
const first = frame.blocks.find((b) => parseMakeBlock(b) !== null || parseRevisionBlock(b) !== null || parsePlanEditBlock(b) !== null);
|
|
679
|
+
frame = { ...frame, blocks: first === undefined ? [] : [first] };
|
|
680
|
+
}
|
|
613
681
|
// DES-CATALOG-002 §4.6: the turn's revision of a held job proposal (or the hold's release), first.
|
|
614
682
|
this.onTurnReply(frame);
|
|
615
683
|
if (frame.blocks.length === 0 || frame.turnId === undefined || !frame.ok)
|
|
616
684
|
return;
|
|
617
685
|
if (!this.deps.flags().proposals)
|
|
618
686
|
return;
|
|
619
|
-
|
|
687
|
+
// DES-CATALOG-002 §2.3: with job routing on, one routing protocol: the FIRST valid block is the one actionable card,
|
|
688
|
+
// and at a job's held plan a plan edit or a change of job becomes wicked's offer instead.
|
|
689
|
+
// An older client (no job cards) keeps today's reading: the last valid block, no plan offers it could not draw.
|
|
690
|
+
const jobs = this.jobsOn() && this.acceptsTurn(frame.chat, frame.turnId);
|
|
691
|
+
if (jobs && this.onPlanReply(frame))
|
|
692
|
+
return;
|
|
693
|
+
const block = jobs ? firstValidBlock(frame.blocks) : lastValidBlock(frame.blocks);
|
|
620
694
|
if (block === null) {
|
|
621
695
|
this.log(`[proposals] chat ${frame.chat}: ${frame.blocks.length} wicked-make block(s) from ${frame.cliKey}, none valid — no card`);
|
|
622
696
|
return;
|
|
@@ -648,9 +722,20 @@ export class ChatProposals {
|
|
|
648
722
|
}
|
|
649
723
|
if (this.deps.instanceOf(frame.chat) !== instance || has())
|
|
650
724
|
return;
|
|
651
|
-
|
|
725
|
+
// An older client draws no job card: its statement asks for the command in prose, and its artifact entries (the
|
|
726
|
+
// documents and the demo) keep today's path.
|
|
727
|
+
const jobBlock = jobs && block.op === 'entry' && isJobCardEntry(block);
|
|
728
|
+
const proposal = jobBlock
|
|
729
|
+
? await this.resolveDetected({ chatId: frame.chat, turnId, seat: frame.cliKey, block: block, records: this.deps.records(frame.chat) })
|
|
730
|
+
: await this.resolve({ chatId: frame.chat, turnId, seat: frame.cliKey, block, records: this.deps.records(frame.chat) });
|
|
652
731
|
if (proposal === null)
|
|
653
732
|
return;
|
|
733
|
+
// A job card never appears after the person has written again (codex r4): a newer message ("never mind") supersedes a
|
|
734
|
+
// slow reply's detection.
|
|
735
|
+
if (jobBlock && this.newerMessage(frame.chat, turnId)) {
|
|
736
|
+
this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s job card came after a newer message — dropped`);
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
654
739
|
// Published under the chat's lock, so it never lands between an accept's checks and its record.
|
|
655
740
|
await this.lock.run(`chat\u0000${instance ?? frame.chat}`, async () => {
|
|
656
741
|
// DES-CATALOG-002 §4.6 (codex r1): a chat whose job lineage is open is changed only through a revision (merged,
|
|
@@ -658,7 +743,7 @@ export class ChatProposals {
|
|
|
658
743
|
const jobOpen = [...foldProposals(this.deps.records(frame.chat)).values()].some((f) => f.proposal.shape !== undefined && (f.state === 'open' || f.state === 'revising'));
|
|
659
744
|
if (jobOpen)
|
|
660
745
|
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())
|
|
746
|
+
else if (!has() && !(jobBlock && this.newerMessage(frame.chat, turnId)))
|
|
662
747
|
this.write(frame.chat, { at: this.now(), turnId, kind: 'proposal', proposal }, instance);
|
|
663
748
|
});
|
|
664
749
|
})
|
|
@@ -666,6 +751,12 @@ export class ChatProposals {
|
|
|
666
751
|
.finally(() => this.pending.delete(job));
|
|
667
752
|
this.pending.add(job);
|
|
668
753
|
}
|
|
754
|
+
/** Whether the person has written again since `turnId` (its reply is then an older one). */
|
|
755
|
+
newerMessage(chatId, turnId) {
|
|
756
|
+
const order = this.deps.records(chatId).filter((r) => r.kind === 'user').map((r) => r.turnId);
|
|
757
|
+
const mine = order.indexOf(turnId);
|
|
758
|
+
return mine !== -1 && mine < order.length - 1;
|
|
759
|
+
}
|
|
669
760
|
/** Append a record and send it on `/ws` — only while the chat is still the instance the caller acted on. */
|
|
670
761
|
write(chatId, record, instance) {
|
|
671
762
|
if (this.deps.instanceOf(chatId) !== instance) {
|
|
@@ -727,6 +818,7 @@ export class ChatProposals {
|
|
|
727
818
|
return this.refused(chatId, 'refine');
|
|
728
819
|
const ref = parseArtifactRef(block.refine);
|
|
729
820
|
let target;
|
|
821
|
+
let protectedList;
|
|
730
822
|
let projectId = chat.projectId;
|
|
731
823
|
if (ref === null) {
|
|
732
824
|
blocked.push(`“${block.refine}” is not a document studio knows`);
|
|
@@ -749,10 +841,19 @@ export class ChatProposals {
|
|
|
749
841
|
else {
|
|
750
842
|
target = { ref: ref.ref, title, base: head };
|
|
751
843
|
projectId = projectOfMount(ref.mount);
|
|
844
|
+
// A5: the person's own edits this revision keeps (Keep it is the default; only they can let one change).
|
|
845
|
+
const touch = [...block.touches, ...(open ? binding?.artifact?.anchors ?? [] : [])];
|
|
846
|
+
const kept = await this.protectedOf(ref.ref, head, touch);
|
|
847
|
+
if ('error' in kept)
|
|
848
|
+
blocked.push(kept.error);
|
|
849
|
+
else
|
|
850
|
+
protectedList = kept.entries;
|
|
752
851
|
}
|
|
753
852
|
}
|
|
754
853
|
}
|
|
755
|
-
|
|
854
|
+
// A5: a change works from the document and the person's words; extra sources do not reach its run yet, so the
|
|
855
|
+
// card says so instead of showing them as used (codex A5 r1).
|
|
856
|
+
const sources = (await this.resolveSources(block.sources, { chatId, turnId, records, binding, turnHas, chat, words, personNamed: false })).map((src) => src.status === 'ok' ? { ...src, status: 'struck', reason: 'a change works from the document and your words; make a new document to use this source' } : src);
|
|
756
857
|
const helpers = this.helpers(chat);
|
|
757
858
|
if (helpers === null)
|
|
758
859
|
blocked.push(NEEDS_HELPER);
|
|
@@ -770,6 +871,7 @@ export class ChatProposals {
|
|
|
770
871
|
filedIn: await filedIn(projectId),
|
|
771
872
|
...(target !== undefined ? { target } : {}),
|
|
772
873
|
...(block.touches.length > 0 ? { touches: block.touches } : {}),
|
|
874
|
+
...(protectedList !== undefined ? { protected: protectedList } : {}),
|
|
773
875
|
blocked: blocked[0] ?? null,
|
|
774
876
|
};
|
|
775
877
|
}
|
|
@@ -945,11 +1047,15 @@ export class ChatProposals {
|
|
|
945
1047
|
const strike = (token, label, reason, projectId) => {
|
|
946
1048
|
push({ token, label, status: 'struck', reason, ...(projectId !== undefined ? { projectId } : {}) });
|
|
947
1049
|
};
|
|
948
|
-
for (const raw of tokens.slice(0, PROPOSAL_SOURCES_MAX)) {
|
|
1050
|
+
for (const raw of ctx.jobDocuments === true ? tokens : tokens.slice(0, PROPOSAL_SOURCES_MAX)) {
|
|
949
1051
|
const token = raw.trim();
|
|
950
1052
|
if (seen.has(token))
|
|
951
1053
|
continue;
|
|
952
1054
|
seen.add(token);
|
|
1055
|
+
if (ctx.jobDocuments === true && !token.startsWith('attachment:') && !token.startsWith('doc:')) {
|
|
1056
|
+
strike(token, token.slice(0, 40), 'a job reads files and documents only');
|
|
1057
|
+
continue;
|
|
1058
|
+
}
|
|
953
1059
|
if (token === 'chat') {
|
|
954
1060
|
push({ token, label: 'this conversation', status: 'ok' });
|
|
955
1061
|
continue;
|
|
@@ -980,9 +1086,9 @@ export class ChatProposals {
|
|
|
980
1086
|
const a = this.deps.attachments(ctx.chatId).find((x) => x.id === id);
|
|
981
1087
|
if (a === undefined)
|
|
982
1088
|
strike(`attachment:${id}`, `attachment ${id.slice(0, 12)}`, 'not a file attached to this chat');
|
|
983
|
-
//
|
|
984
|
-
else if (typeof a.bytes === 'number' && a.bytes > 512 * 1024)
|
|
985
|
-
strike(`attachment:${a.id}`, a.name, 'too large for a document\'s sources (over 512 KB)');
|
|
1089
|
+
// The document packet keeps its 512 KB cap; a job stages whole files up to the upload cap.
|
|
1090
|
+
else if (ctx.packetDocuments !== true && typeof a.bytes === 'number' && a.bytes > (ctx.jobDocuments === true ? ATTACHMENT_MAX_FILE_BYTES : 512 * 1024))
|
|
1091
|
+
strike(`attachment:${a.id}`, a.name, ctx.jobDocuments === true ? 'too large for a job document (over 10 MB)' : 'too large for a document\'s sources (over 512 KB)');
|
|
986
1092
|
else
|
|
987
1093
|
push({ token: `attachment:${a.id}`, label: a.name, status: 'ok' });
|
|
988
1094
|
continue;
|
|
@@ -1075,6 +1181,28 @@ export class ChatProposals {
|
|
|
1075
1181
|
}
|
|
1076
1182
|
return out;
|
|
1077
1183
|
}
|
|
1184
|
+
/** Authorise the files a job reads against this chat, its named documents and its current project scope. */
|
|
1185
|
+
async authorizeDocuments(chatId, tokens) {
|
|
1186
|
+
// Launch-time callers use the latest binding; proposal resolution uses its own turn's snapshot below.
|
|
1187
|
+
return this.authorizeDocumentsAt(chatId, tokens, this.deps.records(chatId), '\u0000');
|
|
1188
|
+
}
|
|
1189
|
+
async authorizeDocumentsAt(chatId, tokens, records, turnId, packetDocuments = false, cache = false) {
|
|
1190
|
+
tokens = tokens.slice(0, 20);
|
|
1191
|
+
const chat = this.deps.chat(chatId);
|
|
1192
|
+
if (chat === null)
|
|
1193
|
+
return [...new Set(tokens.map((t) => t.trim()))].map((token) => ({ token, label: token.slice(0, 40), status: 'struck', reason: 'the chat has ended' }));
|
|
1194
|
+
const scoped = await this.resolveSources(tokens, { chatId, turnId, records, ...bindingOf(records, turnId), chat, words: personWords(records, turnId), personNamed: false, jobDocuments: true, packetDocuments });
|
|
1195
|
+
if (!packetDocuments)
|
|
1196
|
+
return scoped;
|
|
1197
|
+
const deps = this.deps.registry.documentPacketDeps();
|
|
1198
|
+
const planned = deps === null ? [] : await documentPathPlan(scoped.filter((s) => s.status === 'ok').map((s) => s.token), chatId, deps, { cache });
|
|
1199
|
+
return scoped.map((s) => {
|
|
1200
|
+
if (s.status !== 'ok')
|
|
1201
|
+
return s;
|
|
1202
|
+
const plan = planned.find((p) => p.token === s.token);
|
|
1203
|
+
return plan?.status === 'ok' ? s : { ...s, status: 'struck', reason: plan?.reason ?? 'document packet readers are unavailable' };
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1078
1206
|
// ── the answer ───────────────────────────────────────────────────────────────────────────────────────────────────
|
|
1079
1207
|
/**
|
|
1080
1208
|
* `POST /chats/:id/proposals/:pid` after the route's capability, person and owner checks. `instance` is the chat
|
|
@@ -1097,6 +1225,10 @@ export class ChatProposals {
|
|
|
1097
1225
|
if (folded === undefined)
|
|
1098
1226
|
return { code: 404, body: { error: `no proposal ${pid} in chat ${chatId}` } };
|
|
1099
1227
|
const kind = folded.proposal.kind;
|
|
1228
|
+
// (api-types 0.196.0) How it runs is a job's Start's choice, and nothing else's.
|
|
1229
|
+
if (body.power !== undefined && (kind !== 'job' || body.decision !== 'go')) {
|
|
1230
|
+
return { code: 400, body: { code: 'power_not_applicable', error: kind !== 'job' ? 'only a job runs as a power run' : 'how a job runs is chosen with Start, not Not now' } };
|
|
1231
|
+
}
|
|
1100
1232
|
const reread = () => foldProposals(this.deps.records(chatId)).get(pid) ?? folded;
|
|
1101
1233
|
const ok = (f) => ({ code: 200, body: { view: viewOf(f) } });
|
|
1102
1234
|
// 1. What already happened, before any state check.
|
|
@@ -1146,7 +1278,7 @@ export class ChatProposals {
|
|
|
1146
1278
|
throw err;
|
|
1147
1279
|
}
|
|
1148
1280
|
}
|
|
1149
|
-
return this.go(chatId, folded, again, again === acc.resolution ? acc.edits : { ...(acc.edits ?? {}), ...body.edits }, acc.identity, actor, instance);
|
|
1281
|
+
return this.go(chatId, folded, again, again === acc.resolution ? acc.edits : { ...(acc.edits ?? {}), ...body.edits }, acc.identity, actor, instance, body.power);
|
|
1150
1282
|
}
|
|
1151
1283
|
if (folded.state === 'superseded') {
|
|
1152
1284
|
return { code: 409, body: { code: 'proposal_superseded', error: 'a newer proposal in this chat replaced this one', view: viewOf(folded) } };
|
|
@@ -1204,20 +1336,20 @@ export class ChatProposals {
|
|
|
1204
1336
|
if (effective.blocked !== null) {
|
|
1205
1337
|
return { code: 409, body: { code: 'proposal_blocked', error: effective.blocked, view: viewOf(folded) } };
|
|
1206
1338
|
}
|
|
1207
|
-
return this.go(chatId, folded, effective, body.edits ?? null, this.identityOf(effective), actor, instance);
|
|
1339
|
+
return this.go(chatId, folded, effective, body.edits ?? null, this.identityOf(effective), actor, instance, body.power);
|
|
1208
1340
|
}
|
|
1209
1341
|
/**
|
|
1210
1342
|
* The state checks, then `accepting`, the launch, and `decided` — under the chat's lock and the document's, so two
|
|
1211
1343
|
* proposals of one chat (or two chats changing one document) can never both pass the busy check.
|
|
1212
1344
|
*/
|
|
1213
|
-
go(chatId, folded, resolution, edits, identity, actor, instance) {
|
|
1345
|
+
go(chatId, folded, resolution, edits, identity, actor, instance, power) {
|
|
1214
1346
|
const docKey = (resolution.kind === 'refine' || (resolution.kind === 'create' && resolution.artifactRef !== undefined)) && identity.artifactRef !== null ? identity.artifactRef : null;
|
|
1215
1347
|
// Keyed by the chat's instance (shared by its original id and an ended chat's archived alias), else its id.
|
|
1216
1348
|
return this.lock.run(`chat\u0000${instance ?? chatId}`, () => docKey === null
|
|
1217
|
-
? this.goLocked(chatId, folded, resolution, edits, identity, actor, instance)
|
|
1218
|
-
: this.lock.run(`doc\u0000${docKey}`, () => this.goLocked(chatId, folded, resolution, edits, identity, actor, instance)));
|
|
1349
|
+
? this.goLocked(chatId, folded, resolution, edits, identity, actor, instance, power)
|
|
1350
|
+
: this.lock.run(`doc\u0000${docKey}`, () => this.goLocked(chatId, folded, resolution, edits, identity, actor, instance, power)));
|
|
1219
1351
|
}
|
|
1220
|
-
async goLocked(chatId, folded, resolution, edits, identity, actor, instance) {
|
|
1352
|
+
async goLocked(chatId, folded, resolution, edits, identity, actor, instance, power) {
|
|
1221
1353
|
const kind = resolution.kind;
|
|
1222
1354
|
const pid = resolution.pid;
|
|
1223
1355
|
// Under the chat's lock: a newer proposal published while this one was being checked supersedes it.
|
|
@@ -1265,7 +1397,8 @@ export class ChatProposals {
|
|
|
1265
1397
|
const gone = await this.firstGone(chatId, resolution);
|
|
1266
1398
|
if (gone !== null)
|
|
1267
1399
|
return { code: 409, body: { code: 'source_gone', error: gone, view: viewOf(folded) } };
|
|
1268
|
-
|
|
1400
|
+
// A theme is no job (§15.2): applying colours never waits for a run of this chat.
|
|
1401
|
+
const busy = kind === 'theme' ? null : await this.busy(chatId, identity.artifactRef, resolution);
|
|
1269
1402
|
if (busy !== null)
|
|
1270
1403
|
return { code: 409, body: { code: busy.code, error: busy.reason, view: viewOf(folded) } };
|
|
1271
1404
|
// A refine is on the head it was proposed on; else the card re-resolves (same pid, the new base). Read last, right
|
|
@@ -1282,7 +1415,7 @@ export class ChatProposals {
|
|
|
1282
1415
|
const pids = [...foldProposals(this.deps.records(chatId)).keys()];
|
|
1283
1416
|
if (pids.indexOf(pid) < pids.length - 1) {
|
|
1284
1417
|
const recordedOld = folded.proposal;
|
|
1285
|
-
const freshOld = { ...recordedOld, target: { ...(recordedOld.target ?? resolution.target), base: head } };
|
|
1418
|
+
const freshOld = await this.onNewHead({ ...recordedOld, target: { ...(recordedOld.target ?? resolution.target), base: head } });
|
|
1286
1419
|
if (!this.write(chatId, { at: this.now(), turnId: folded.turnId, kind: 'proposal', proposal: freshOld }, instance))
|
|
1287
1420
|
return this.gone(chatId);
|
|
1288
1421
|
const settled = foldProposals(this.deps.records(chatId)).get(pid);
|
|
@@ -1290,7 +1423,7 @@ export class ChatProposals {
|
|
|
1290
1423
|
}
|
|
1291
1424
|
// From the proposal as crew recorded it (never the refused request's edits): the person chooses again.
|
|
1292
1425
|
const recorded = folded.proposal;
|
|
1293
|
-
const fresh = { ...recorded, target: { ...(recorded.target ?? resolution.target), base: head } };
|
|
1426
|
+
const fresh = await this.onNewHead({ ...recorded, target: { ...(recorded.target ?? resolution.target), base: head } });
|
|
1294
1427
|
if (!this.write(chatId, { at: this.now(), turnId: folded.turnId, kind: 'proposal', proposal: fresh }, instance))
|
|
1295
1428
|
return this.gone(chatId);
|
|
1296
1429
|
const after = foldProposals(this.deps.records(chatId)).get(pid);
|
|
@@ -1307,12 +1440,19 @@ export class ChatProposals {
|
|
|
1307
1440
|
if (why !== null)
|
|
1308
1441
|
return { code: 409, body: { code: 'proposal_blocked', error: why, view: viewOf(folded) } };
|
|
1309
1442
|
}
|
|
1443
|
+
// (api-types 0.196.0, operator ruling 2026-11-06) A power Start runs as one, or is refused before anything is
|
|
1444
|
+
// recorded: never started phased behind the person's back.
|
|
1445
|
+
if (power === true) {
|
|
1446
|
+
const why = this.deps.powerRefusal === undefined ? "this daemon can't start a chat job as a power run; press Start with Review plan on" : await this.deps.powerRefusal(resolution);
|
|
1447
|
+
if (why !== null)
|
|
1448
|
+
return { code: 409, body: { code: 'power_unavailable', error: why, view: viewOf(folded) } };
|
|
1449
|
+
}
|
|
1310
1450
|
// §2.5: a reshape (or its corrected descendant) answers the held plan Reject first, in this one transition; the
|
|
1311
1451
|
// proposal then records that it did, so a retry launches without asking again.
|
|
1312
1452
|
if (resolution.reshapes !== undefined && resolution.heldRejected !== true) {
|
|
1313
1453
|
if (this.deps.reshapeReject === undefined)
|
|
1314
1454
|
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);
|
|
1455
|
+
const refused = await this.deps.reshapeReject(resolution.reshapes, actor, pid, resolution.heldPlan);
|
|
1316
1456
|
if (refused !== null)
|
|
1317
1457
|
return refused;
|
|
1318
1458
|
resolution = { ...resolution, heldRejected: true };
|
|
@@ -1325,27 +1465,50 @@ export class ChatProposals {
|
|
|
1325
1465
|
return this.gone(chatId);
|
|
1326
1466
|
let result;
|
|
1327
1467
|
try {
|
|
1328
|
-
result = await this.deps.registry.launchOnce({ kind, pid, chatId, actor, identity, resolution });
|
|
1468
|
+
result = await this.deps.registry.launchOnce({ kind, pid, chatId, actor, identity, resolution, ...(power !== undefined ? { power } : {}) });
|
|
1329
1469
|
}
|
|
1330
1470
|
catch (err) {
|
|
1331
1471
|
// Accepting stays recorded: the card shows "Interrupted · Go again", which resumes the same identity.
|
|
1332
1472
|
const msg = err instanceof Error ? err.message : String(err);
|
|
1333
|
-
this.deps.audit('chat.proposal.launch_failed', actor, { chatId, pid, error: msg });
|
|
1473
|
+
this.deps.audit('chat.proposal.launch_failed', actor, { chatId, pid, error: msg, ...(power !== undefined ? { power } : {}) });
|
|
1334
1474
|
const after = foldProposals(this.deps.records(chatId)).get(pid);
|
|
1335
1475
|
return { code: 502, body: { code: 'launch_failed', error: `could not start it: ${msg}. Go again resumes the same job.`, ...(after !== undefined ? { view: viewOf(after) } : {}) } };
|
|
1336
1476
|
}
|
|
1337
|
-
if (!this.decided(chatId, folded.turnId, pid, actor, 'go', result, resolution, edits, instance))
|
|
1477
|
+
if (!this.decided(chatId, folded.turnId, pid, actor, 'go', result, resolution, edits, instance, power))
|
|
1338
1478
|
return this.gone(chatId);
|
|
1339
1479
|
const after = foldProposals(this.deps.records(chatId)).get(pid) ?? folded;
|
|
1340
1480
|
return { code: 200, body: { view: viewOf(after) } };
|
|
1341
1481
|
}
|
|
1342
1482
|
/** Record the answer (and audit exactly what was answered); `false` when the chat is no longer this instance. */
|
|
1343
|
-
decided(chatId, turnId, pid, actor, decision, result, resolution, edits, instance) {
|
|
1483
|
+
decided(chatId, turnId, pid, actor, decision, result, resolution, edits, instance, power) {
|
|
1344
1484
|
if (!this.write(chatId, { at: this.now(), turnId, kind: 'proposal_decided', pid, actor: actor.id, decision, result }, instance))
|
|
1345
1485
|
return false;
|
|
1346
|
-
this.deps.audit(decision === 'go' ? 'chat.proposal.accepted' : 'chat.proposal.declined', actor, { chatId, pid, kind: resolution.kind, resolution, edits, result });
|
|
1486
|
+
this.deps.audit(decision === 'go' ? 'chat.proposal.accepted' : 'chat.proposal.declined', actor, { chatId, pid, kind: resolution.kind, resolution, edits, result, ...(power !== undefined ? { power } : {}) });
|
|
1347
1487
|
return true;
|
|
1348
1488
|
}
|
|
1489
|
+
/** A5: the protected edits of a document at a version, or the reason a refine card is blocked. */
|
|
1490
|
+
async protectedOf(ref, version, touch) {
|
|
1491
|
+
if (this.deps.protectedEdits === undefined)
|
|
1492
|
+
return { entries: [] };
|
|
1493
|
+
const r = await this.deps.protectedEdits(ref, version, touch).catch((err) => ({ ok: false, error: err instanceof Error ? err.message : String(err) }));
|
|
1494
|
+
return r.ok ? { entries: r.entries } : { error: `Your own edits can't be checked on this host, so it can't be changed from chat (${r.error.slice(0, 200)})` };
|
|
1495
|
+
}
|
|
1496
|
+
/** A5: a refine at the document's current head (and that head's protected edits); unchanged when it is gone. */
|
|
1497
|
+
async refreshTarget(p) {
|
|
1498
|
+
const ref = p.target === undefined ? null : parseArtifactRef(p.target.ref);
|
|
1499
|
+
const root = ref === null ? null : await this.deps.docsRoot(ref.projectId);
|
|
1500
|
+
const head = root === null || ref === null ? null : artifactHead(root, ref.doc);
|
|
1501
|
+
if (head === null || p.target === undefined)
|
|
1502
|
+
return p;
|
|
1503
|
+
return this.onNewHead({ ...p, target: { ...p.target, base: head } });
|
|
1504
|
+
}
|
|
1505
|
+
/** A5: a refine card re-resolved on a newer head: its protected edits are those of the new head (Keep preselected). */
|
|
1506
|
+
async onNewHead(p) {
|
|
1507
|
+
if (p.kind !== 'refine' || p.target === undefined)
|
|
1508
|
+
return p;
|
|
1509
|
+
const kept = await this.protectedOf(p.target.ref, p.target.base, p.touches ?? []);
|
|
1510
|
+
return 'error' in kept ? { ...p, protected: [], blocked: kept.error } : { ...p, protected: kept.entries, blocked: p.blocked };
|
|
1511
|
+
}
|
|
1349
1512
|
/** The identity a Go is named by (DES §4.3 step 2). */
|
|
1350
1513
|
identityOf(p) {
|
|
1351
1514
|
const runId = proposalRunId(p.pid);
|
|
@@ -1366,6 +1529,11 @@ export class ChatProposals {
|
|
|
1366
1529
|
*/
|
|
1367
1530
|
async firstGone(chatId, p) {
|
|
1368
1531
|
let runs = null;
|
|
1532
|
+
const documents = p.sentence?.tokens.flatMap((t) => t.kind === 'documents' ? t.documents ?? [] : []) ?? [];
|
|
1533
|
+
const checked = documents.length === 0 ? [] : await this.authorizeDocumentsAt(chatId, documents.filter((s) => s.status === 'ok').map((s) => s.token), this.deps.records(chatId), '\u0000', p.kind === 'create');
|
|
1534
|
+
const struck = checked.find((s) => s.status === 'struck');
|
|
1535
|
+
if (struck !== undefined)
|
|
1536
|
+
return `${struck.label} cannot be used (${struck.reason})`;
|
|
1369
1537
|
// A3: a repository the card names must still be registered (never silently dropped from the launch).
|
|
1370
1538
|
if ((p.repoRefs ?? []).length > 0 && this.deps.repoIds !== undefined) {
|
|
1371
1539
|
const have = await this.deps.repoIds();
|
|
@@ -1373,7 +1541,7 @@ export class ChatProposals {
|
|
|
1373
1541
|
if (lost !== -1)
|
|
1374
1542
|
return `${p.repos[lost] ?? p.repoRefs[lost]} is no longer registered on this daemon; ask again in the chat`;
|
|
1375
1543
|
}
|
|
1376
|
-
for (const s of p.sources) {
|
|
1544
|
+
for (const s of [...p.sources, ...documents]) {
|
|
1377
1545
|
if (s.status !== 'ok')
|
|
1378
1546
|
continue;
|
|
1379
1547
|
if (s.token.startsWith('run:')) {
|
|
@@ -1451,7 +1619,7 @@ export class ChatProposals {
|
|
|
1451
1619
|
return this.applyJobEdits(chatId, f, edits);
|
|
1452
1620
|
const allowed = {
|
|
1453
1621
|
create: p.artifactRef !== undefined ? ['title', 'brief', 'sources', 'helpers'] : ['title', 'brief', 'sources', 'helpers', 'repos', 'project'],
|
|
1454
|
-
refine: ['ask', 'helpers'],
|
|
1622
|
+
refine: ['ask', 'helpers', 'allow'],
|
|
1455
1623
|
theme: ['name', 'patch'],
|
|
1456
1624
|
demo: ['audience', 'show', 'helpers'],
|
|
1457
1625
|
};
|
|
@@ -1479,6 +1647,14 @@ export class ChatProposals {
|
|
|
1479
1647
|
throw new EditRefusal('the ask must be 1 to 4000 characters');
|
|
1480
1648
|
next = { ...next, brief: a };
|
|
1481
1649
|
}
|
|
1650
|
+
if (edits.allow !== undefined) {
|
|
1651
|
+
// A5 (§6.2): only the person releases a protected edit, and only one the card shows them (an id names one exact
|
|
1652
|
+
// value; an edit made since the card was drawn has a new id and is kept).
|
|
1653
|
+
const shown = new Set((p.protected ?? []).map((e) => e.id));
|
|
1654
|
+
if (!Array.isArray(edits.allow) || edits.allow.length > 500 || edits.allow.some((id) => typeof id !== 'string' || !shown.has(id))) {
|
|
1655
|
+
throw new EditRefusal('only edits shown on this card can be let change; check the card again');
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1482
1658
|
if (edits.audience !== undefined || edits.show !== undefined) {
|
|
1483
1659
|
if ((edits.audience?.length ?? 0) > 400 || (edits.show?.length ?? 0) > 2000)
|
|
1484
1660
|
throw new EditRefusal('the audience or what to show is too long');
|
|
@@ -1644,6 +1820,319 @@ export class ChatProposals {
|
|
|
1644
1820
|
acceptsJobs(chatId) {
|
|
1645
1821
|
return this.jobsOn() && this.deps.acceptsJobs?.(chatId) === true;
|
|
1646
1822
|
}
|
|
1823
|
+
/** Holds whose release waits for the held-plan path's outcome (`<chat>\0<turn>`). */
|
|
1824
|
+
deferredRelease = new Set();
|
|
1825
|
+
/** Turns whose held-plan work is queued (set before the turn's own release runs; pi r8: a deferral only ever waits on
|
|
1826
|
+
* work that exists). */
|
|
1827
|
+
planScheduled = new Set();
|
|
1828
|
+
/** Per accepted turn: whether its client draws job cards, as the turn's instructions were written (codex r3). */
|
|
1829
|
+
turnAccepts = new Map();
|
|
1830
|
+
/** The route records the declaration a turn's instructions were written for, before the seat can answer it. */
|
|
1831
|
+
noteTurnAccepts(chatId, turnId, accepts) {
|
|
1832
|
+
this.turnAccepts.set(`${chatId}\u0000${turnId}`, accepts);
|
|
1833
|
+
while (this.turnAccepts.size > 2000)
|
|
1834
|
+
this.turnAccepts.delete(this.turnAccepts.keys().next().value);
|
|
1835
|
+
}
|
|
1836
|
+
/** How a reply to `turnId` is read: as its instructions were written, else the chat's declaration now. */
|
|
1837
|
+
acceptsTurn(chatId, turnId) {
|
|
1838
|
+
const noted = turnId === undefined ? undefined : this.turnAccepts.get(`${chatId}\u0000${turnId}`);
|
|
1839
|
+
return this.jobsOn() && (noted ?? this.deps.acceptsJobs?.(chatId) === true);
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* (DES-CATALOG-002 §2.3) A seat's job routing block → a DETECTED job proposal: the block is a guess like any other,
|
|
1843
|
+
* validated against the catalog, cross-checked with the words layer over the person's own message of that turn and
|
|
1844
|
+
* banded (the chat door is capped at likely unless the words agree). An unsure reading is ONE question: the proposal
|
|
1845
|
+
* holds no Start, and its `shape.guess.question` lists the shapes to pick from (a pick is a person-made proposal).
|
|
1846
|
+
* `null` when nothing can be proposed (the chat ended, an analysis, a refusal).
|
|
1847
|
+
*/
|
|
1848
|
+
async resolveDetected(input) {
|
|
1849
|
+
const { chatId, turnId, seat, block, records } = input;
|
|
1850
|
+
const chat = this.deps.chat(chatId);
|
|
1851
|
+
if (chat === null)
|
|
1852
|
+
return null;
|
|
1853
|
+
if (chat.analysis) {
|
|
1854
|
+
this.log(`[proposals] chat ${chatId} is an analysis: it proposes nothing — no card`);
|
|
1855
|
+
return null;
|
|
1856
|
+
}
|
|
1857
|
+
const jc = this.jobChat(chatId);
|
|
1858
|
+
if (jc === null)
|
|
1859
|
+
return null;
|
|
1860
|
+
const pid = `${chatId}:${turnId}`;
|
|
1861
|
+
// The whole message: the job's words are what the person said, never silently clipped (codex r2).
|
|
1862
|
+
const words = turnWords(records, turnId);
|
|
1863
|
+
try {
|
|
1864
|
+
const ctx = await this.jobContext(chatId, pid, turnId, seat, jc, { revises: null, lineage: null, notes: [] });
|
|
1865
|
+
const available = (card, option) => resolveOption(card, option, ctx.served)?.resolved.status === 'available';
|
|
1866
|
+
const d = detect({
|
|
1867
|
+
text: words,
|
|
1868
|
+
seat: { entry: block.entry, option: block.option ?? null, depth: block.depth ?? null, confidence: block.confidence, reason: block.reason },
|
|
1869
|
+
source: 'chat',
|
|
1870
|
+
catalogRev: ctx.served.rev,
|
|
1871
|
+
available,
|
|
1872
|
+
});
|
|
1873
|
+
const g = d.guess;
|
|
1874
|
+
// The repository the block names, when it is one of this chat's (else the chat's own rule picks it).
|
|
1875
|
+
const named = block.repos.map((want) => jc.repos.filter((r) => r.name === want || r.id === want)).find((hits) => hits.length === 1)?.[0];
|
|
1876
|
+
// A demo's address only from the person's own words (DES-CHAT-ARTIFACTS-001 §4.3), never the model's.
|
|
1877
|
+
const inputs = {};
|
|
1878
|
+
if (block.url !== undefined && block.url !== '' && personUrls(words).has(block.url))
|
|
1879
|
+
inputs['url'] = { kind: 'url', value: block.url };
|
|
1880
|
+
const facts = {
|
|
1881
|
+
card: g.card,
|
|
1882
|
+
option: g.option,
|
|
1883
|
+
depth: g.depth,
|
|
1884
|
+
words,
|
|
1885
|
+
details: [],
|
|
1886
|
+
repoRef: named?.id ?? null,
|
|
1887
|
+
projectId: jc.projectId,
|
|
1888
|
+
lead: null,
|
|
1889
|
+
seats: null,
|
|
1890
|
+
inputs,
|
|
1891
|
+
skipQe: null,
|
|
1892
|
+
by: 'detected',
|
|
1893
|
+
source: 'chat',
|
|
1894
|
+
guess: g,
|
|
1895
|
+
};
|
|
1896
|
+
// ONE question, never a Start, while the reading is unsure: each choice names a shape (a pick is a person-made
|
|
1897
|
+
// proposal).
|
|
1898
|
+
const proposal = withAskOverlay(await this.proposalOf(chatId, pid, facts, ctx, records));
|
|
1899
|
+
this.deps.audit('chat.detect', { id: `seat:${seat}`, kind: 'agent', trust: 'observer' }, {
|
|
1900
|
+
chatId, turnId, source: g.source, seat, card: g.card, option: g.option, band: g.band, confidence: g.confidence, dropped: d.seat?.dropped ?? null,
|
|
1901
|
+
});
|
|
1902
|
+
return proposal;
|
|
1903
|
+
}
|
|
1904
|
+
catch (err) {
|
|
1905
|
+
const refused = this.refusalOf(err);
|
|
1906
|
+
if (refused === null)
|
|
1907
|
+
throw err;
|
|
1908
|
+
this.log(`[proposals] chat ${chatId}: turn ${turnId}'s job block could not be proposed (${String(refused.body.code ?? refused.code)})`);
|
|
1909
|
+
return null;
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
/** The chat's newest job that Go started: its proposal and run (`null` when none). */
|
|
1913
|
+
launchedJob(chatId) {
|
|
1914
|
+
const folded = [...foldProposals(this.deps.records(chatId)).values()];
|
|
1915
|
+
for (let i = folded.length - 1; i >= 0; i -= 1) {
|
|
1916
|
+
const f = folded[i];
|
|
1917
|
+
if (f.state === 'decided' && f.decision === 'go' && f.result?.runId !== undefined && f.proposal.kind === 'job' && f.proposal.shape !== undefined) {
|
|
1918
|
+
return { proposal: f.accepting?.resolution ?? f.proposal, runId: f.result.runId };
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
return null;
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* (DES-CATALOG-002 §2.4, §2.5) Typed at a job's held plan without Change: the seat's `planEdit` block becomes wicked's
|
|
1925
|
+
* send-back offer quoting the person's own words, and a revision block that changes the job's card, option or depth
|
|
1926
|
+
* becomes the "start it again as…" offer naming what it gives up and what it needs. An offer decides nothing: only the
|
|
1927
|
+
* person's press calls the gate or the reshape route, bound to the plan version. `true` when the reply was one of these
|
|
1928
|
+
* (handled here, whatever the outcome); `false` to read it as anything else.
|
|
1929
|
+
*/
|
|
1930
|
+
onPlanReply(frame) {
|
|
1931
|
+
const turnId = frame.turnId;
|
|
1932
|
+
if (turnId === undefined || this.deps.heldPlan === undefined)
|
|
1933
|
+
return false;
|
|
1934
|
+
const job = this.launchedJob(frame.chat);
|
|
1935
|
+
if (job === null)
|
|
1936
|
+
return false;
|
|
1937
|
+
let planEdit = null;
|
|
1938
|
+
let rev = null;
|
|
1939
|
+
for (const b of frame.blocks) {
|
|
1940
|
+
planEdit ??= parsePlanEditBlock(b);
|
|
1941
|
+
const r = parseRevisionBlock(b);
|
|
1942
|
+
if (rev === null && r !== null && r.revises === job.proposal.pid)
|
|
1943
|
+
rev = r;
|
|
1944
|
+
}
|
|
1945
|
+
if (planEdit === null && rev === null)
|
|
1946
|
+
return false;
|
|
1947
|
+
const instance = this.deps.instanceOf(frame.chat);
|
|
1948
|
+
let published = false;
|
|
1949
|
+
const scheduledKey = `${frame.chat}\u0000${turnId}`;
|
|
1950
|
+
this.planScheduled.add(scheduledKey);
|
|
1951
|
+
const work = this.order.run(`chat\u0000${frame.chat}`, async () => {
|
|
1952
|
+
try {
|
|
1953
|
+
await this.planReplyWork(frame, turnId, job, planEdit, rev, instance, () => {
|
|
1954
|
+
published = true;
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
finally {
|
|
1958
|
+
this.planScheduled.delete(scheduledKey);
|
|
1959
|
+
// A hold this turn's message took on another open proposal is released now, saying whether the change landed.
|
|
1960
|
+
const key = `${frame.chat}\u0000${turnId}`;
|
|
1961
|
+
if (this.deferredRelease.delete(key)) {
|
|
1962
|
+
try {
|
|
1963
|
+
await this.lock.run(`chat\u0000${instance ?? frame.chat}`, async () => {
|
|
1964
|
+
const f = [...foldProposals(this.deps.records(frame.chat)).values()].find((x) => x.state === 'revising' && x.hold === turnId);
|
|
1965
|
+
if (f !== undefined)
|
|
1966
|
+
this.write(frame.chat, { at: this.now(), turnId, kind: 'proposal_released', pid: f.proposal.pid, note: published ? null : "Your change wasn't applied: say it again." }, instance);
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
finally {
|
|
1970
|
+
const n = (this.settling.get(key) ?? 1) - 1;
|
|
1971
|
+
if (n <= 0)
|
|
1972
|
+
this.settling.delete(key);
|
|
1973
|
+
else
|
|
1974
|
+
this.settling.set(key, n);
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
})
|
|
1979
|
+
.catch((err) => this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s plan offer failed: ${err instanceof Error ? err.message : String(err)}`))
|
|
1980
|
+
.finally(() => this.pending.delete(work));
|
|
1981
|
+
this.pending.add(work);
|
|
1982
|
+
return true;
|
|
1983
|
+
}
|
|
1984
|
+
async planReplyWork(frame, turnId, job, planEdit, rev, instance, onPublished) {
|
|
1985
|
+
{
|
|
1986
|
+
if (this.deps.instanceOf(frame.chat) !== instance)
|
|
1987
|
+
return;
|
|
1988
|
+
if (planEdit !== null && planEdit !== job.runId) {
|
|
1989
|
+
this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s plan edit names ${planEdit.slice(0, 64)}, not the chat's job ${job.runId} — dropped`);
|
|
1990
|
+
return;
|
|
1991
|
+
}
|
|
1992
|
+
// One offer per turn, and never from a reply older than the chat's newest message (a slow seat's late answer
|
|
1993
|
+
// must not replace a newer offer on the same plan version).
|
|
1994
|
+
const isNewest = () => {
|
|
1995
|
+
const rs = this.deps.records(frame.chat);
|
|
1996
|
+
const order = rs.filter((r) => r.kind === 'user').map((r) => r.turnId);
|
|
1997
|
+
const mine = order.indexOf(turnId);
|
|
1998
|
+
return !rs.some((r) => r.kind === 'plan_offer' && r.turnId === turnId) && (mine === -1 || mine === order.length - 1);
|
|
1999
|
+
};
|
|
2000
|
+
if (!isNewest())
|
|
2001
|
+
return;
|
|
2002
|
+
const held = await this.deps.heldPlan(job.runId);
|
|
2003
|
+
if (held === null || held.state !== 'held') {
|
|
2004
|
+
this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s plan reply, but job ${job.runId} is not waiting at its plan — no offer`);
|
|
2005
|
+
return;
|
|
2006
|
+
}
|
|
2007
|
+
// The person's words, waited for as the turn's own record (the route writes it after the engine took it).
|
|
2008
|
+
for (let i = 0; i < 25 && turnWords(this.deps.records(frame.chat), turnId) === ''; i += 1)
|
|
2009
|
+
await new Promise((res) => setTimeout(res, 200));
|
|
2010
|
+
const message = turnWords(this.deps.records(frame.chat), turnId).trim();
|
|
2011
|
+
const base = { id: `${frame.chat}:offer:${turnId}`, runId: job.runId, pid: job.proposal.pid, ord: held.ord, planRev: held.planRev };
|
|
2012
|
+
let offer = null;
|
|
2013
|
+
const shapeEdit = rev === null ? null : { ...(rev.edits.card !== undefined ? { card: rev.edits.card } : {}), ...(rev.edits.option !== undefined ? { option: rev.edits.option } : {}), ...(rev.edits.depth !== undefined ? { depth: rev.edits.depth } : {}) };
|
|
2014
|
+
if (shapeEdit !== null && Object.keys(shapeEdit).length > 0) {
|
|
2015
|
+
if (!held.reshapeable) {
|
|
2016
|
+
this.log(`[proposals] chat ${frame.chat}: turn ${turnId} changes the job, but its work plan was already accepted — no reshape offer`);
|
|
2017
|
+
return;
|
|
2018
|
+
}
|
|
2019
|
+
offer = await this.reshapeOffer(frame.chat, job.proposal, shapeEdit, base);
|
|
2020
|
+
}
|
|
2021
|
+
else if (planEdit !== null) {
|
|
2022
|
+
if (message === '')
|
|
2023
|
+
return;
|
|
2024
|
+
const leadKey = held.lead ?? job.proposal.seats?.lead ?? null;
|
|
2025
|
+
const lead = leadKey === null ? 'the lead' : (this.deps.rosterEligible().find((s) => s.key === leadKey)?.name ?? leadKey);
|
|
2026
|
+
// The person's message whole: the lead reads every word of it (only the offer's line shows a preview).
|
|
2027
|
+
const note = message;
|
|
2028
|
+
offer = {
|
|
2029
|
+
...base,
|
|
2030
|
+
kind: 'send_back',
|
|
2031
|
+
text: `Send it back to ${lead} with: “${note.length > 200 ? `${note.slice(0, 199)}…` : note}”?`,
|
|
2032
|
+
note,
|
|
2033
|
+
choices: [{ label: 'Send it back', action: 'send_back' }, { label: 'No', action: 'dismiss' }],
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
if (offer === null)
|
|
2037
|
+
return;
|
|
2038
|
+
// Published under the chat's lock, re-checked there (a newer message may have landed while it resolved).
|
|
2039
|
+
await this.lock.run(`chat\u0000${instance ?? frame.chat}`, async () => {
|
|
2040
|
+
if (this.deps.instanceOf(frame.chat) !== instance || !isNewest())
|
|
2041
|
+
return;
|
|
2042
|
+
if (this.write(frame.chat, { at: this.now(), turnId, kind: 'plan_offer', offer: offer }, instance))
|
|
2043
|
+
onPublished();
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
/** The "start it again as…" offer: the new shape resolved like a revision, its losses and missing inputs named. */
|
|
2048
|
+
async reshapeOffer(chatId, held, edits, base) {
|
|
2049
|
+
const chat = this.jobChat(chatId);
|
|
2050
|
+
if (chat === null)
|
|
2051
|
+
return null;
|
|
2052
|
+
const ctx = await this.jobContext(chatId, base.id, null, 'person', chat, { revises: held.pid, lineage: held.lineage ?? held.pid, notes: [] });
|
|
2053
|
+
const merged = await this.mergeJobRevision(held, edits, ctx);
|
|
2054
|
+
const card = CATALOG_V2_CARDS.find((c) => c.id === merged.facts.card);
|
|
2055
|
+
if (card === undefined || (merged.facts.card === held.shape?.card && optionFor(card, merged.facts.option) === held.shape?.option && merged.facts.depth === held.shape?.depth))
|
|
2056
|
+
return null;
|
|
2057
|
+
const option = optionFor(card, merged.facts.option);
|
|
2058
|
+
let needs = [];
|
|
2059
|
+
let command = card.command;
|
|
2060
|
+
try {
|
|
2061
|
+
const p = await this.proposalOf(chatId, base.id, { ...merged.facts, by: 'person', source: 'reshape' }, ctx, this.deps.records(chatId), false, held);
|
|
2062
|
+
if (p.kind !== 'job') {
|
|
2063
|
+
this.log(`[proposals] chat ${chatId}: a change of job to ${card.id} makes a document — no reshape offer (it is a new proposal)`);
|
|
2064
|
+
return null;
|
|
2065
|
+
}
|
|
2066
|
+
if (p.coming !== undefined)
|
|
2067
|
+
return null;
|
|
2068
|
+
needs = (p.needs ?? []).filter((n) => n.required && n.status === 'missing').map((n) => n.label);
|
|
2069
|
+
command = p.command ?? command;
|
|
2070
|
+
}
|
|
2071
|
+
catch (err) {
|
|
2072
|
+
if (this.refusalOf(err) === null)
|
|
2073
|
+
throw err;
|
|
2074
|
+
return null;
|
|
2075
|
+
}
|
|
2076
|
+
const noun = nounOf(card, option);
|
|
2077
|
+
const words = [...merged.lost.map((g) => checksLabel([g])), ...merged.lostSeats.map((k) => SEAT_WORDS[k])];
|
|
2078
|
+
const lostText = words.length <= 1 ? (words[0] ?? '') : `${words.slice(0, -1).join(', ')} and ${words[words.length - 1]}`;
|
|
2079
|
+
const text = [
|
|
2080
|
+
`That's a different job: start it again as ${noun}?`,
|
|
2081
|
+
...(words.length > 0 ? [`It would no longer have ${lostText}.`] : []),
|
|
2082
|
+
...(needs.length > 0 ? [`It needs: ${needs.join(', ')}.`] : []),
|
|
2083
|
+
'Edits to this plan are not carried.',
|
|
2084
|
+
].join(' ');
|
|
2085
|
+
return {
|
|
2086
|
+
...base,
|
|
2087
|
+
kind: 'reshape',
|
|
2088
|
+
text,
|
|
2089
|
+
reshape: { card: card.id, option, depth: merged.facts.depth, label: nounOf(card, option), command: command ?? null, lost: merged.lost, lostSeats: merged.lostSeats, needs },
|
|
2090
|
+
choices: [{ label: 'Start again', action: 'reshape' }, { label: 'Keep this plan', action: 'dismiss' }],
|
|
2091
|
+
};
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* (DES-CATALOG-002 §2.3, §4.6) The per-message job lines for this chat: how it routes new work, the chat catalog
|
|
2095
|
+
* digest, and what is open, held at its plan or running. `null` when job routing is off.
|
|
2096
|
+
*/
|
|
2097
|
+
async jobTurn(chatId, accepts) {
|
|
2098
|
+
if (!this.jobsOn())
|
|
2099
|
+
return null;
|
|
2100
|
+
// The earlier turns' proposals are published first (codex r5): the ids this turn is told are the ones its hold binds.
|
|
2101
|
+
await this.order.run(`chat\u0000${chatId}`, async () => undefined);
|
|
2102
|
+
const mode = (accepts ?? this.acceptsJobs(chatId)) ? 'cards' : 'prose';
|
|
2103
|
+
const chat = this.jobChat(chatId);
|
|
2104
|
+
let status;
|
|
2105
|
+
try {
|
|
2106
|
+
const served = await this.deps.served(chat?.projectId ?? null);
|
|
2107
|
+
status = (card, option) => resolveOption(card, option, served)?.resolved.status ?? 'unavailable';
|
|
2108
|
+
}
|
|
2109
|
+
catch {
|
|
2110
|
+
status = undefined;
|
|
2111
|
+
}
|
|
2112
|
+
const context = { digest: catalogDigest('chat', status !== undefined ? { status } : {}) };
|
|
2113
|
+
if (mode === 'prose') {
|
|
2114
|
+
// The command line names the command: the chat digest's cards with their commands.
|
|
2115
|
+
context.digest = `${context.digest}\nCommands: ${CATALOG_V2_CARDS.filter((c) => detectable(c) && c.command !== null).map((c) => `${c.id} ${c.command}`).join('; ')}.`;
|
|
2116
|
+
return { mode, context };
|
|
2117
|
+
}
|
|
2118
|
+
const open = [...foldProposals(this.deps.records(chatId)).values()].find((f) => (f.state === 'open' || f.state === 'revising') && f.proposal.shape !== undefined);
|
|
2119
|
+
if (open !== undefined) {
|
|
2120
|
+
const p = open.proposal;
|
|
2121
|
+
context.open = { pid: p.pid, label: p.what.label, card: p.shape.card, option: p.shape.option, repo: p.repos[0] ?? null, seats: [...(p.seats?.keys ?? [])], checks: checksLabel(p.gate ?? []) };
|
|
2122
|
+
}
|
|
2123
|
+
const job = this.launchedJob(chatId);
|
|
2124
|
+
if (job !== null && this.deps.heldPlan !== undefined) {
|
|
2125
|
+
const held = await this.deps.heldPlan(job.runId).catch(() => null);
|
|
2126
|
+
if (held?.state === 'held') {
|
|
2127
|
+
const leadKey = held.lead ?? job.proposal.seats?.lead ?? null;
|
|
2128
|
+
context.heldPlan = { runId: job.runId, pid: job.proposal.pid, label: job.proposal.what.label, version: held.planRev, lead: leadKey === null ? null : (this.deps.rosterEligible().find((s) => s.key === leadKey)?.name ?? leadKey) };
|
|
2129
|
+
}
|
|
2130
|
+
else if (held?.state === 'running') {
|
|
2131
|
+
context.running = { runId: job.runId, label: job.proposal.what.label };
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
return { mode, context };
|
|
2135
|
+
}
|
|
1647
2136
|
/** The chat as a job's resolution sees it, or `null` once it has ended. */
|
|
1648
2137
|
jobChat(chatId) {
|
|
1649
2138
|
const c = this.deps.chat(chatId);
|
|
@@ -1661,7 +2150,86 @@ export class ChatProposals {
|
|
|
1661
2150
|
}
|
|
1662
2151
|
const projectLabel = chat.projectId === null ? 'Not in a project · this chat' : ((await this.deps.projectName(chat.projectId)) ?? chat.projectId);
|
|
1663
2152
|
const qeOff = (await this.deps.qeOff?.().catch(() => false)) === true;
|
|
1664
|
-
|
|
2153
|
+
const powerPresets = (await this.deps.powerPresets?.(chat.projectId).catch(() => null)) ?? null;
|
|
2154
|
+
return { chatId, pid, turnId, seat, chat, served, roster: this.deps.rosterEligible(), projectLabel, qeOff, powerPresets, ...extra };
|
|
2155
|
+
}
|
|
2156
|
+
/** Source availability matters only to a card that shows this input. Keep a failed read a named refusal. */
|
|
2157
|
+
async loadJobSources(facts, ctx) {
|
|
2158
|
+
const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
|
|
2159
|
+
const r = card === undefined ? null : resolveOption(card.id, optionFor(card, facts.option), ctx.served);
|
|
2160
|
+
if (!r?.resolved.inputs.some((i) => i.id === 'sources') || ctx.jobSources !== undefined)
|
|
2161
|
+
return;
|
|
2162
|
+
try {
|
|
2163
|
+
const sources = await this.deps.jobSources?.(ctx.chat.projectId);
|
|
2164
|
+
if (sources !== undefined)
|
|
2165
|
+
ctx.jobSources = sources;
|
|
2166
|
+
if (sources !== undefined && !sources.some((s) => s.web === true)) {
|
|
2167
|
+
// A reason only: a failed read keeps the plain fallback, never refuses the proposal.
|
|
2168
|
+
const why = await this.deps.webReason?.(ctx.chat.projectId).catch(() => undefined);
|
|
2169
|
+
if (why !== undefined)
|
|
2170
|
+
ctx.webReason = why;
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
catch (err) {
|
|
2174
|
+
throw new JobRefusal('sources_unavailable', err instanceof Error ? err.message : String(err), 409);
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
/** (CJ13) The last authors read per repository and words, for a short while: a revision and its rebuild, and a run
|
|
2178
|
+
* of swaps, read the change once (a failed read is never kept). */
|
|
2179
|
+
reviewAuthorsSeen = new Map();
|
|
2180
|
+
/**
|
|
2181
|
+
* (CJ13) A review of a change is never led or checked by a seat that wrote it: the launch drops the change's authors
|
|
2182
|
+
* from its roster, so the proposal's seats are chosen without them (the default lead included) and the passage names
|
|
2183
|
+
* none of them. The change is read from the words the launch reads (the brief and its input lines). A read that
|
|
2184
|
+
* fails, or that would leave no seat, keeps the roster: the launch then decides (it refuses an author named as
|
|
2185
|
+
* primary, and a roster of authors only as `no_independent_reviewer`).
|
|
2186
|
+
*/
|
|
2187
|
+
async reviewRoster(facts, ctx) {
|
|
2188
|
+
const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
|
|
2189
|
+
const r = card === undefined ? null : resolveOption(card.id, optionFor(card, facts.option), ctx.served);
|
|
2190
|
+
const repo = repoOf(facts, ctx.chat);
|
|
2191
|
+
if (r?.workflow !== REVIEW_CHANGE_WORKFLOW || repo === null || this.deps.reviewAuthors === undefined)
|
|
2192
|
+
return ctx;
|
|
2193
|
+
const words = [briefOf(facts), ...inputLines({ inputs: facts.inputs })].join('\n\n');
|
|
2194
|
+
const key = `${repo.id}\u0000${words}`;
|
|
2195
|
+
const now = Date.now();
|
|
2196
|
+
let authors = this.reviewAuthorsSeen.get(key);
|
|
2197
|
+
if (authors === undefined || now - authors.at > 30_000) {
|
|
2198
|
+
const read = await this.deps.reviewAuthors(repo.id, words).catch(() => null);
|
|
2199
|
+
if (read === null)
|
|
2200
|
+
return ctx;
|
|
2201
|
+
authors = { at: now, authors: read };
|
|
2202
|
+
for (const [k, v] of this.reviewAuthorsSeen)
|
|
2203
|
+
if (now - v.at > 30_000)
|
|
2204
|
+
this.reviewAuthorsSeen.delete(k);
|
|
2205
|
+
this.reviewAuthorsSeen.set(key, authors);
|
|
2206
|
+
}
|
|
2207
|
+
const roster = ctx.roster.filter((s) => !authors.authors.includes(s.key));
|
|
2208
|
+
return roster.length === 0 || roster.length === ctx.roster.length ? ctx : { ...ctx, roster };
|
|
2209
|
+
}
|
|
2210
|
+
/** Resolve the revision's shape first, then load only the choices that its input checks need. */
|
|
2211
|
+
async mergeJobRevision(parent, edits, ctx) {
|
|
2212
|
+
const shape = mergeRevision(parent, {
|
|
2213
|
+
...(edits.card !== undefined ? { card: edits.card } : {}),
|
|
2214
|
+
...(edits.option !== undefined ? { option: edits.option } : {}),
|
|
2215
|
+
}, ctx).facts;
|
|
2216
|
+
await this.loadJobSources(shape, ctx);
|
|
2217
|
+
// (CJ13) The seats are checked against the authors of the change the revision names (its words, details, inputs
|
|
2218
|
+
// and repository may all move the target), so it is merged once to read them.
|
|
2219
|
+
const reviewCtx = await this.reviewRoster(mergeRevision(parent, edits, ctx).facts, ctx);
|
|
2220
|
+
const merged = mergeRevision(parent, edits, reviewCtx);
|
|
2221
|
+
// Seats carried from a version that reviewed another change may all be the new change's authors: then they are
|
|
2222
|
+
// picked again from the reviewers left (the lead stays when it still may lead). Seats this revision names itself
|
|
2223
|
+
// are the person's choice and are never replaced (a choice of authors only is short, and its Start is refused).
|
|
2224
|
+
const named = edits.lead !== undefined || edits.addSeats !== undefined || edits.removeSeats !== undefined;
|
|
2225
|
+
const left = new Set(reviewCtx.roster.map((s) => s.key));
|
|
2226
|
+
const authors = new Set(ctx.roster.map((s) => s.key).filter((k) => !left.has(k)));
|
|
2227
|
+
const seats = merged.facts.seats;
|
|
2228
|
+
if (reviewCtx !== ctx && !named && seats !== null && seats.length > 0 && seats.every((k) => authors.has(k))) {
|
|
2229
|
+
const lead = merged.facts.lead !== null && left.has(merged.facts.lead) ? merged.facts.lead : null;
|
|
2230
|
+
return { ...merged, facts: { ...merged.facts, seats: null, lead } };
|
|
2231
|
+
}
|
|
2232
|
+
return merged;
|
|
1665
2233
|
}
|
|
1666
2234
|
/** Job proposals are on: the flag, the catalog read and the operation. */
|
|
1667
2235
|
jobsOn() {
|
|
@@ -1681,15 +2249,33 @@ export class ChatProposals {
|
|
|
1681
2249
|
if (!this.deps.flags().create)
|
|
1682
2250
|
throw new JobRefusal('operation_unavailable', 'studio cannot start a document from a chat on this daemon yet', 409);
|
|
1683
2251
|
const turnId = ctx.turnId ?? `person:${pid.slice(pid.lastIndexOf(':') + 1)}`;
|
|
1684
|
-
|
|
2252
|
+
// Crew's kind line goes first, as `withBriefLines` puts it on a run: a long request is cut at its end, never the line.
|
|
2253
|
+
const words = [r.resolved.brief ?? '', briefOf(facts)].filter((x) => x !== '').join('\n\n');
|
|
1685
2254
|
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
2255
|
if (made === null)
|
|
1687
2256
|
throw new JobRefusal('operation_unavailable', 'studio cannot start a document from a chat on this daemon yet', 409);
|
|
1688
2257
|
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
2258
|
const kindTok = { id: 'kind', kind: (card.variant !== undefined ? 'option' : 'card'), label: nounOf(card, shape.option), swap: null };
|
|
1690
2259
|
const checksTok = { id: 'checks', kind: 'checks', label: checksLabel(r.resolved.gate), swap: null };
|
|
2260
|
+
const documentsInput = r.resolved.inputs.find((i) => i.id === 'documents');
|
|
2261
|
+
const documents = ctx.documents ?? [];
|
|
2262
|
+
const ok = documents.filter((s) => s.status === 'ok');
|
|
2263
|
+
const label = `${ok.length} document${ok.length === 1 ? '' : 's'}`;
|
|
2264
|
+
const needs = documentsInput === undefined ? [] : [{ ...documentsInput, status: ok.length > 0 ? 'met' : 'missing', value: label }];
|
|
2265
|
+
const why = documents.find((s) => s.status === 'struck')?.reason;
|
|
2266
|
+
const question = documentsInput?.required === true && ok.length === 0
|
|
2267
|
+
? { kind: 'missing', text: `Which documents?${why !== undefined ? ` ${why}` : ''}`, choices: [] }
|
|
2268
|
+
: null;
|
|
2269
|
+
const documentsTok = documentsInput === undefined ? [] : [{ id: 'documents', kind: 'documents', label, swap: null, documents }];
|
|
2270
|
+
// A document option this engine cannot draft (Respond and Rework without `interactive-draft-sourced`) is said, with
|
|
2271
|
+
// why, and offers no Start (CS8).
|
|
2272
|
+
const offline = r.resolved.status !== 'available' ? (r.resolved.statusNote ?? `${card.title} can't start on this daemon`) : null;
|
|
1691
2273
|
return {
|
|
1692
2274
|
...made,
|
|
2275
|
+
// These tokens passed the document packet's plan, including PDF text and the shared budget. Keep that
|
|
2276
|
+
// decision rather than applying the legacy source count cap or CS4's larger job limits.
|
|
2277
|
+
...(documentsInput !== undefined ? { sources: [...made.sources, ...ok], inputs: { ...facts.inputs }, needs } : {}),
|
|
2278
|
+
blocked: made.blocked ?? offline ?? question?.text ?? null,
|
|
1693
2279
|
pid,
|
|
1694
2280
|
turnId: ctx.turnId,
|
|
1695
2281
|
// `what.entry` stays the document entry the create launcher reads its style from (codex r1); the card is in `shape`.
|
|
@@ -1701,22 +2287,41 @@ export class ChatProposals {
|
|
|
1701
2287
|
gate: [...r.resolved.gate],
|
|
1702
2288
|
words: facts.words,
|
|
1703
2289
|
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 },
|
|
2290
|
+
sentence: { text: `I'll make {kind} from this conversation${documentsInput !== undefined ? ', reading {documents}' : ''}, filed in ${made.filedIn.label}, checked by {checks}.`, tokens: [kindTok, ...documentsTok, checksTok], notes: [...ctx.notes], ask: offline !== null ? null : question?.text ?? (made.blocked === null ? 'Start?' : null) },
|
|
1705
2291
|
suggestions: [],
|
|
1706
|
-
question
|
|
2292
|
+
question,
|
|
1707
2293
|
revises: ctx.revises,
|
|
1708
2294
|
lineage: ctx.lineage ?? pid,
|
|
1709
2295
|
...(ctx.answers !== undefined ? { answers: ctx.answers } : {}),
|
|
1710
2296
|
...(ctx.request !== undefined ? { request: ctx.request } : {}),
|
|
1711
2297
|
};
|
|
1712
2298
|
}
|
|
1713
|
-
/** Resolve facts to
|
|
1714
|
-
async proposalOf(chatId, pid, facts, ctx, records, allowHidden = false) {
|
|
2299
|
+
/** Resolve facts to their proposal. `previous` marks a rebuild; null is a held job without a stored parent. */
|
|
2300
|
+
async proposalOf(chatId, pid, facts, ctx, records, allowHidden = false, previous) {
|
|
1715
2301
|
const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
|
|
1716
2302
|
const r = card === undefined ? null : resolveOption(card.id, optionFor(card, facts.option), ctx.served);
|
|
2303
|
+
await this.loadJobSources(facts, ctx);
|
|
2304
|
+
ctx = await this.reviewRoster(facts, ctx);
|
|
2305
|
+
if (r?.resolved.inputs.some((i) => i.id === 'documents')) {
|
|
2306
|
+
if (facts.inputs['documents'] === undefined) {
|
|
2307
|
+
const { binding } = bindingOf(records, ctx.turnId ?? '\u0000');
|
|
2308
|
+
// A rebuild never discovers new files. Only a fresh card, or a switch from a card without documents, fills.
|
|
2309
|
+
const fill = previous === undefined || (previous !== null && previous.shape?.card !== facts.card && !previous.needs?.some((n) => n.id === 'documents'));
|
|
2310
|
+
const tokens = fill ? [...new Set([
|
|
2311
|
+
...this.deps.attachments(chatId).map((a) => `attachment:${a.id}`),
|
|
2312
|
+
...(binding?.named.docs ?? []).map((ref) => `doc:${ref}`),
|
|
2313
|
+
...(binding?.artifact !== undefined ? [`doc:${binding.artifact.ref}`] : []),
|
|
2314
|
+
])].slice(0, 20) : [];
|
|
2315
|
+
// Persist even an empty fill, so factsOf cannot pick up files the person never saw.
|
|
2316
|
+
facts = { ...facts, inputs: { ...facts.inputs, documents: { kind: 'documents', tokens } } };
|
|
2317
|
+
}
|
|
2318
|
+
const input = facts.inputs['documents'];
|
|
2319
|
+
ctx = { ...ctx, documents: await this.authorizeDocumentsAt(chatId, input?.kind === 'documents' ? input.tokens : [], records, ctx.turnId ?? '\u0000', r !== null && proposalKindOf(r) === 'create', true) };
|
|
2320
|
+
}
|
|
2321
|
+
// An unsure reading holds no Start wherever the proposal is rebuilt (a Go's edits, a refresh; codex r4).
|
|
1717
2322
|
if (r !== null && proposalKindOf(r) === 'create')
|
|
1718
|
-
return this.documentProposal(chatId, pid, facts, ctx, records);
|
|
1719
|
-
return resolveJob(facts, ctx, { allowHidden });
|
|
2323
|
+
return withAskOverlay(await this.documentProposal(chatId, pid, facts, ctx, records));
|
|
2324
|
+
return withAskOverlay(resolveJob(facts, ctx, { allowHidden }));
|
|
1720
2325
|
}
|
|
1721
2326
|
refusalOf(err) {
|
|
1722
2327
|
if (err instanceof JobRefusal)
|
|
@@ -1725,6 +2330,17 @@ export class ChatProposals {
|
|
|
1725
2330
|
return { code: 400, body: { code: 'edits_invalid', error: err.message } };
|
|
1726
2331
|
return null;
|
|
1727
2332
|
}
|
|
2333
|
+
/** Explicit file edits refuse any struck token; a rebuild refuses a downgrade of a file the person saw as ok. */
|
|
2334
|
+
refuseStruckDocuments(p, previous) {
|
|
2335
|
+
const wasOk = previous?.sentence?.tokens.flatMap((t) => t.kind === 'documents' ? t.documents ?? [] : []).filter((s) => s.status === 'ok').map((s) => s.token) ?? [];
|
|
2336
|
+
const struck = p.sentence?.tokens.flatMap((t) => t.kind === 'documents' ? t.documents ?? [] : []).find((s) => s.status === 'struck' && (previous === undefined || wasOk.includes(s.token)));
|
|
2337
|
+
if (struck === undefined)
|
|
2338
|
+
return;
|
|
2339
|
+
const why = `${struck.label} cannot be used (${struck.reason})`;
|
|
2340
|
+
if (previous !== undefined)
|
|
2341
|
+
throw new JobRefusal('source_gone', why, 409);
|
|
2342
|
+
throw new EditRefusal(why);
|
|
2343
|
+
}
|
|
1728
2344
|
/**
|
|
1729
2345
|
* `POST /chats/:id/proposals` after the route's capability, person and owner checks: a person-made proposal (a `/`
|
|
1730
2346
|
* pick, a typed command, a question's choice) or a revision (a swap, a suggestion, a question's choice). No seat turn
|
|
@@ -1854,7 +2470,56 @@ export class ChatProposals {
|
|
|
1854
2470
|
else
|
|
1855
2471
|
extraNotes.push('Not changed: QE acceptance stays. Skipping it needs your own reason, in your own words.');
|
|
1856
2472
|
}
|
|
1857
|
-
|
|
2473
|
+
// What a seat's block carries into the brief must be the person's own (codex r3): a detail added or removed, and a
|
|
2474
|
+
// text input, appear in their message (outside quotes and reported speech); anything else is refused with a note.
|
|
2475
|
+
if (!fromPerson) {
|
|
2476
|
+
const said = ownWords(src.message ?? '').toLowerCase();
|
|
2477
|
+
const fromThem = (t) => t.trim() !== '' && said.includes(t.trim().toLowerCase());
|
|
2478
|
+
if (edits.detail !== undefined) {
|
|
2479
|
+
const add = (edits.detail.add ?? []).filter((d) => fromThem(d));
|
|
2480
|
+
// A removal needs the person to ask for one, and a carried fact that names a check is never dropped from a
|
|
2481
|
+
// seat's block (codex r4: "keep a separate judge" mentions the detail, it does not remove it).
|
|
2482
|
+
// The removal verb belongs to THIS detail: within a few words before it (pi r5).
|
|
2483
|
+
const asksRemoval = (d) => {
|
|
2484
|
+
const at = said.indexOf(d.trim().toLowerCase());
|
|
2485
|
+
if (at === -1)
|
|
2486
|
+
return false;
|
|
2487
|
+
const before = said.slice(Math.max(0, at - 60), at);
|
|
2488
|
+
// The removal verb in the same clause, right before the detail, and not itself negated ("do not remove …").
|
|
2489
|
+
const m = /\b(?:remove|drop|forget|scrap|undo|take\s+out|no\s+longer|don'?t\s+need)\b(?:\s+[^\s.;,]+){0,4}\s*$/iu.exec(before);
|
|
2490
|
+
// Not negated, and no keeping or new clause between the verb and the detail ("remove X and keep <detail>").
|
|
2491
|
+
return m !== null && !/\b(?:don'?t|do\s+not|never|not)\s+$/iu.test(before.slice(0, m.index)) && !/\b(?:keep|keeping|retain|retaining|and|but|then|while|whilst)\b/iu.test(before.slice(m.index).replace(/^\S+/u, ''));
|
|
2492
|
+
};
|
|
2493
|
+
const namesCheck = (d) => /\b(?:reviews?|reviewers?|judges?|parity|qe|acceptance|tests?|checks?|cited\s+findings|floor|gates?)\b/iu.test(d);
|
|
2494
|
+
const remove = (edits.detail.remove ?? []).filter((d) => fromThem(d) && asksRemoval(d) && !namesCheck(d));
|
|
2495
|
+
for (const d of edits.detail.add ?? [])
|
|
2496
|
+
if (!fromThem(d))
|
|
2497
|
+
extraNotes.push(`Not changed: “${d.slice(0, 60)}” isn't in what you said`);
|
|
2498
|
+
for (const d of edits.detail.remove ?? [])
|
|
2499
|
+
if (!remove.includes(d))
|
|
2500
|
+
extraNotes.push(`Not changed: “${d.slice(0, 60)}” stays (say to remove it${namesCheck(d) ? '; it names a check, so it stays' : ''})`);
|
|
2501
|
+
edits.detail = { ...(add.length > 0 ? { add } : {}), ...(remove.length > 0 ? { remove } : {}) };
|
|
2502
|
+
}
|
|
2503
|
+
if (edits.inputs !== undefined) {
|
|
2504
|
+
const kept = {};
|
|
2505
|
+
for (const [k, v] of Object.entries(edits.inputs)) {
|
|
2506
|
+
if (v.kind === 'requirements' || v.kind === 'documents' || v.kind === 'sources' || fromThem(v.value))
|
|
2507
|
+
kept[k] = v;
|
|
2508
|
+
else
|
|
2509
|
+
extraNotes.push(`Not changed: ${k.slice(0, 40)} must be in your own words`);
|
|
2510
|
+
}
|
|
2511
|
+
edits.inputs = kept;
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
// The job's own words are the person's (§4.6 rule 6): a seat's block may fill a missing intent, never replace it
|
|
2515
|
+
// (codex r1 on Lane D: the brief the lead reads is never the seat's rewrite).
|
|
2516
|
+
if (!fromPerson && edits.inputs !== undefined && Object.hasOwn(edits.inputs, 'intent') && (parent.proposal.words ?? '').trim() !== '') {
|
|
2517
|
+
const { intent: _dropped, ...rest } = edits.inputs;
|
|
2518
|
+
void _dropped;
|
|
2519
|
+
edits.inputs = rest;
|
|
2520
|
+
extraNotes.push("Not changed: the job's own words are yours; say them again to change them");
|
|
2521
|
+
}
|
|
2522
|
+
const merged = await this.mergeJobRevision(parent.proposal, edits, ctx0);
|
|
1858
2523
|
merged.notes.push(...extraNotes);
|
|
1859
2524
|
const ctx = { ...ctx0, notes: merged.notes };
|
|
1860
2525
|
// A hidden card stays reachable while the revision keeps it (it was reached by its alias once).
|
|
@@ -1863,8 +2528,24 @@ export class ChatProposals {
|
|
|
1863
2528
|
// are compared with the parent's too, so nothing is lost unseen (codex r2).
|
|
1864
2529
|
let candidate = null;
|
|
1865
2530
|
let candidateErr = null;
|
|
2531
|
+
// A revision is not the detection any more: a changed card or option drops the guess it no longer describes (codex
|
|
2532
|
+
// r2), and an unsure guess is cleared only by a revision that names the shape (a card or an option: the seat's
|
|
2533
|
+
// reading of the person's clarification, the same card included); a repository or a detail leaves the question
|
|
2534
|
+
// standing (codex r3).
|
|
2535
|
+
const g = merged.facts.guess;
|
|
2536
|
+
const seed = CATALOG_V2_CARDS.find((c) => c.id === merged.facts.card);
|
|
2537
|
+
// Named AND taken: a refused card or option leaves the question standing (codex r4).
|
|
2538
|
+
const namesShape = seed !== undefined
|
|
2539
|
+
&& (rev.edits.card !== undefined || rev.edits.option !== undefined)
|
|
2540
|
+
&& (rev.edits.card === undefined || rev.edits.card === merged.facts.card)
|
|
2541
|
+
&& (rev.edits.option === undefined || optionFor(seed, rev.edits.option ?? undefined) === optionFor(seed, merged.facts.option ?? undefined));
|
|
2542
|
+
const moved = g !== undefined && (seed === undefined || g.card !== merged.facts.card || optionFor(seed, g.option) !== optionFor(seed, merged.facts.option));
|
|
2543
|
+
const stale = g !== undefined && (moved || (g.band === 'ask' && namesShape));
|
|
1866
2544
|
try {
|
|
1867
|
-
|
|
2545
|
+
const { guess: _g, ...unguessed } = merged.facts;
|
|
2546
|
+
void _g;
|
|
2547
|
+
const factsNow = stale ? unguessed : merged.facts;
|
|
2548
|
+
candidate = withAskOverlay(keepReshape(await this.proposalOf(chatId, src.pid, { ...factsNow, by: fromPerson ? 'person' : factsNow.by, source: src.source }, ctx, records, allowHidden, parent.proposal), parent.proposal));
|
|
1868
2549
|
}
|
|
1869
2550
|
catch (err) {
|
|
1870
2551
|
candidateErr = err;
|
|
@@ -1893,7 +2574,7 @@ export class ChatProposals {
|
|
|
1893
2574
|
return { code: 409, body: { code: 'card_not_available', error: candidate.blocked, view: viewOf(parent) } };
|
|
1894
2575
|
}
|
|
1895
2576
|
if (qe !== null || (loses && !covered)) {
|
|
1896
|
-
const base = keepReshape(await this.proposalOf(chatId, src.pid, factsOf(parent.proposal), ctx, records, true), parent.proposal);
|
|
2577
|
+
const base = keepReshape(await this.proposalOf(chatId, src.pid, factsOf(parent.proposal), ctx, records, true, parent.proposal), parent.proposal);
|
|
1897
2578
|
const newCard = CATALOG_V2_CARDS.find((c) => c.id === merged.facts.card);
|
|
1898
2579
|
const oldCard = CATALOG_V2_CARDS.find((c) => c.id === parent.proposal.shape.card);
|
|
1899
2580
|
const newNoun = nounOf(newCard, optionFor(newCard, merged.facts.option));
|
|
@@ -1935,7 +2616,7 @@ export class ChatProposals {
|
|
|
1935
2616
|
return { code: 201, body: { view: view !== undefined ? viewOf(view) : { proposal: asked, state: 'open' } } };
|
|
1936
2617
|
}
|
|
1937
2618
|
// 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)
|
|
2619
|
+
if (!fromPerson && merged.unchanged && merged.notes.length === 0 && !stale)
|
|
1939
2620
|
return { code: 200, body: { view: viewOf(parent) } };
|
|
1940
2621
|
if (candidate === null)
|
|
1941
2622
|
throw candidateErr;
|
|
@@ -2006,8 +2687,12 @@ export class ChatProposals {
|
|
|
2006
2687
|
const message = this.deps.records(frame.chat).find((r) => r.kind === 'user' && r.turnId === turnId && r.owner === true)?.text ?? null;
|
|
2007
2688
|
try {
|
|
2008
2689
|
const out = await this.reviseLocked(frame.chat, rev, { person: null, source: 'chat', pid: `${frame.chat}:${turnId}`, turnId, message }, instance);
|
|
2009
|
-
if (out.code >= 400)
|
|
2690
|
+
if (out.code >= 400) {
|
|
2691
|
+
// Said, not only logged (codex r6): the proposal is startable again as it was, and the person knows why.
|
|
2692
|
+
const why = out.body.error;
|
|
2693
|
+
note = `Your change wasn't applied${typeof why === 'string' && why !== '' ? `: ${why.slice(0, 160)}` : ''}.`;
|
|
2010
2694
|
this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s revision was refused (${String(out.body.code ?? out.code)})`);
|
|
2695
|
+
}
|
|
2011
2696
|
}
|
|
2012
2697
|
catch (err) {
|
|
2013
2698
|
note = "Your change wasn't applied: say it again.";
|
|
@@ -2015,6 +2700,16 @@ export class ChatProposals {
|
|
|
2015
2700
|
}
|
|
2016
2701
|
}
|
|
2017
2702
|
else if (rev !== null) {
|
|
2703
|
+
if (this.planScheduled.has(key)) {
|
|
2704
|
+
// It names the chat's launched job: the held-plan path answers it, and releases this hold after it, saying
|
|
2705
|
+
// whether an offer came of it (codex r7).
|
|
2706
|
+
this.deferredRelease.add(key);
|
|
2707
|
+
// Still settling until the plan path releases it: a chat read must not reopen it first (codex r8).
|
|
2708
|
+
this.settling.set(key, (this.settling.get(key) ?? 0) + 1);
|
|
2709
|
+
return;
|
|
2710
|
+
}
|
|
2711
|
+
// Said, not silently dropped: the person's change did not land (codex r5).
|
|
2712
|
+
note = "Your change wasn't applied: say it again.";
|
|
2018
2713
|
this.log(`[proposals] chat ${frame.chat}: turn ${turnId}'s revision names ${rev.revises}, not the proposal its message held — dropped`);
|
|
2019
2714
|
}
|
|
2020
2715
|
}
|
|
@@ -2071,7 +2766,7 @@ export class ChatProposals {
|
|
|
2071
2766
|
...(edits.inputs !== undefined ? { inputs: edits.inputs } : {}),
|
|
2072
2767
|
};
|
|
2073
2768
|
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 =
|
|
2769
|
+
const merged = await this.mergeJobRevision(f.proposal, rev, ctx);
|
|
2075
2770
|
if (edits.seats !== undefined) {
|
|
2076
2771
|
const sr = f.proposal.shape === undefined ? null : resolveOption(f.proposal.shape.card, f.proposal.shape.option, ctx.served);
|
|
2077
2772
|
if (sr?.workflow !== null && sr?.workflow !== undefined && SELF_SEATED.has(sr.workflow))
|
|
@@ -2087,7 +2782,13 @@ export class ChatProposals {
|
|
|
2087
2782
|
if (merged.lost.length > 0 || merged.lostSeats.length > 0) {
|
|
2088
2783
|
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
2784
|
}
|
|
2090
|
-
|
|
2785
|
+
if (edits.inputs?.['documents'] === undefined) {
|
|
2786
|
+
const gone = await this.firstGone(chatId, f.proposal);
|
|
2787
|
+
if (gone !== null)
|
|
2788
|
+
throw new JobRefusal('source_gone', gone, 409);
|
|
2789
|
+
}
|
|
2790
|
+
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), f.proposal);
|
|
2791
|
+
this.refuseStruckDocuments(out, edits.inputs?.['documents'] === undefined ? f.proposal : undefined);
|
|
2091
2792
|
if (out.kind !== 'job')
|
|
2092
2793
|
throw new EditRefusal('that option makes a document: pick it in the chat');
|
|
2093
2794
|
const dropped = (f.proposal.gate ?? []).filter((g) => !(out.gate ?? []).includes(g));
|
|
@@ -2121,10 +2822,12 @@ export class ChatProposals {
|
|
|
2121
2822
|
lead: p.seats?.lead ?? null,
|
|
2122
2823
|
seats: p.seats?.keys ?? [],
|
|
2123
2824
|
};
|
|
2124
|
-
|
|
2825
|
+
// One refresh suffix, not one per refresh: the id stays bounded however often the catalog changes (codex r2).
|
|
2826
|
+
const pid = `${p.pid.replace(/(?::c:[0-9a-z]+)+$/u, '')}:c:${this.now().toString(36)}`;
|
|
2125
2827
|
let ctx;
|
|
2126
2828
|
try {
|
|
2127
2829
|
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.'] });
|
|
2830
|
+
await this.loadJobSources(factsOf(p), ctx);
|
|
2128
2831
|
}
|
|
2129
2832
|
catch (err) {
|
|
2130
2833
|
const refused = this.refusalOf(err);
|
|
@@ -2138,7 +2841,7 @@ export class ChatProposals {
|
|
|
2138
2841
|
return null;
|
|
2139
2842
|
let fresh;
|
|
2140
2843
|
try {
|
|
2141
|
-
fresh = keepReshape(await this.proposalOf(chatId, pid, factsOf(p), ctx, this.deps.records(chatId), true), p);
|
|
2844
|
+
fresh = keepReshape(await this.proposalOf(chatId, pid, factsOf(p), ctx, this.deps.records(chatId), true, p), p);
|
|
2142
2845
|
}
|
|
2143
2846
|
catch (err) {
|
|
2144
2847
|
const refused = this.refusalOf(err);
|
|
@@ -2200,20 +2903,32 @@ export class ChatProposals {
|
|
|
2200
2903
|
const heldP = parent?.accepting?.resolution ?? parent?.proposal;
|
|
2201
2904
|
let facts = x.facts;
|
|
2202
2905
|
if (heldP?.shape !== undefined) {
|
|
2203
|
-
const merged =
|
|
2906
|
+
const merged = await this.mergeJobRevision(heldP, x.edits, ctx);
|
|
2204
2907
|
// Nothing is answered for a shape, or an input, that is not the one asked for (codex r3, r4).
|
|
2205
2908
|
const wantCard = CATALOG_V2_CARDS.find((c) => c.id === (x.edits.card ?? merged.facts.card));
|
|
2206
2909
|
const norm = (o) => (wantCard === undefined ? null : o === null || o === undefined ? (wantCard.variant?.default ?? null) : o);
|
|
2207
2910
|
const optionOk = wantCard !== undefined && (x.edits.option === undefined || norm(merged.facts.option) === norm(x.edits.option));
|
|
2208
2911
|
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)));
|
|
2912
|
+
const inputsOk = merged.refusedInputs.length === 0 && 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
2913
|
if (wantCard === undefined || merged.facts.card !== wantCard.id || !optionOk || !depthOk || !inputsOk) {
|
|
2211
2914
|
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
2915
|
}
|
|
2213
|
-
|
|
2916
|
+
// A reshape is the person's shape: no detection guess describing the held job rides on it (codex r3).
|
|
2917
|
+
const { guess: _old, ...personFacts } = merged.facts;
|
|
2918
|
+
void _old;
|
|
2919
|
+
facts = { ...personFacts, skipQe: null, by: 'person', source: 'reshape' };
|
|
2214
2920
|
ctx.notes.push(...merged.notes);
|
|
2215
2921
|
}
|
|
2216
|
-
|
|
2922
|
+
if (heldP !== undefined && x.edits.inputs?.['documents'] === undefined) {
|
|
2923
|
+
const gone = await this.firstGone(chatId, heldP);
|
|
2924
|
+
if (gone !== null)
|
|
2925
|
+
throw new JobRefusal('source_gone', gone, 409);
|
|
2926
|
+
}
|
|
2927
|
+
proposal = await this.proposalOf(chatId, x.pid, facts, ctx, this.deps.records(chatId), false, heldP ?? null);
|
|
2928
|
+
if (x.edits.inputs?.['documents'] !== undefined)
|
|
2929
|
+
this.refuseStruckDocuments(proposal);
|
|
2930
|
+
else if (heldP !== undefined)
|
|
2931
|
+
this.refuseStruckDocuments(proposal, heldP);
|
|
2217
2932
|
}
|
|
2218
2933
|
catch (err) {
|
|
2219
2934
|
const refused = this.refusalOf(err);
|
|
@@ -2238,7 +2953,7 @@ export class ChatProposals {
|
|
|
2238
2953
|
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
2954
|
}
|
|
2240
2955
|
}
|
|
2241
|
-
proposal = { ...proposal, reshapes: x.oldRunId, relaunch: x.relaunch, ...(x.reducedAssurance ? { reducedAssurance: true } : {}) };
|
|
2956
|
+
proposal = { ...proposal, reshapes: x.oldRunId, relaunch: x.relaunch, ...(x.reducedAssurance ? { reducedAssurance: true } : {}), ...(x.heldPlan !== undefined ? { heldPlan: x.heldPlan } : {}) };
|
|
2242
2957
|
if (!this.write(chatId, { at: this.now(), turnId: `reshape:${x.oldRunId}`, kind: 'proposal', proposal }, instance))
|
|
2243
2958
|
return this.gone(chatId);
|
|
2244
2959
|
folded = foldProposals(this.deps.records(chatId)).get(x.pid);
|
|
@@ -2335,14 +3050,20 @@ export class ChatProposals {
|
|
|
2335
3050
|
const pid = `${base.chatId}:retry:${runId}`;
|
|
2336
3051
|
if (folded.has(pid))
|
|
2337
3052
|
return pid;
|
|
3053
|
+
// A5 (codex r1): a refine's retry is drawn on the document as it is now (a conflict moved its head), with the
|
|
3054
|
+
// protected edits of that head, Keep preselected for every one.
|
|
3055
|
+
const fresh = base.kind === 'refine' && base.target !== undefined ? await this.refreshTarget(base) : base;
|
|
2338
3056
|
const retry = {
|
|
2339
|
-
...
|
|
3057
|
+
...fresh,
|
|
2340
3058
|
pid,
|
|
2341
3059
|
turnId: null,
|
|
2342
3060
|
sourceRunId: runId,
|
|
2343
3061
|
artifactRef,
|
|
2344
|
-
reason:
|
|
2345
|
-
|
|
3062
|
+
reason: base.kind === 'refine'
|
|
3063
|
+
? `The last change was not applied: ${reason}. Try again revises the latest version, and keeps your edits.`
|
|
3064
|
+
: `The last attempt ended without a draft: ${reason}. Try again fills the same document.`,
|
|
3065
|
+
// A refine whose edits cannot be read on the new head stays blocked with why (codex A5 r2).
|
|
3066
|
+
blocked: fresh !== base ? fresh.blocked : null,
|
|
2346
3067
|
};
|
|
2347
3068
|
return this.write(chatId, { at: this.now(), turnId: failed.turnId, kind: 'proposal', proposal: retry }, instance) ? pid : null;
|
|
2348
3069
|
});
|