@cleocode/core 2026.6.12 → 2026.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/conduit/local-transport.d.ts +12 -0
- package/dist/conduit/local-transport.d.ts.map +1 -1
- package/dist/conduit/local-transport.js +53 -23
- package/dist/conduit/local-transport.js.map +1 -1
- package/dist/crypto/credentials.d.ts +37 -0
- package/dist/crypto/credentials.d.ts.map +1 -1
- package/dist/crypto/credentials.js +110 -0
- package/dist/crypto/credentials.js.map +1 -1
- package/dist/dispatch/contracts/derive-output-contract.d.ts +86 -0
- package/dist/dispatch/contracts/derive-output-contract.d.ts.map +1 -0
- package/dist/dispatch/contracts/derive-output-contract.js +347 -0
- package/dist/dispatch/contracts/derive-output-contract.js.map +1 -0
- package/dist/dispatch/contracts/ensures-schema.d.ts +77 -0
- package/dist/dispatch/contracts/ensures-schema.d.ts.map +1 -0
- package/dist/dispatch/contracts/ensures-schema.js +91 -0
- package/dist/dispatch/contracts/ensures-schema.js.map +1 -0
- package/dist/dispatch/contracts/output-contracts.d.ts +27 -5
- package/dist/dispatch/contracts/output-contracts.d.ts.map +1 -1
- package/dist/dispatch/contracts/output-contracts.js +29 -6
- package/dist/dispatch/contracts/output-contracts.js.map +1 -1
- package/dist/docs/export-document.js +2294 -1250
- package/dist/docs/export-document.js.map +3 -3
- package/dist/go/driver.d.ts +132 -7
- package/dist/go/driver.d.ts.map +1 -1
- package/dist/go/driver.js +135 -10
- package/dist/go/driver.js.map +1 -1
- package/dist/go/index.d.ts +1 -1
- package/dist/go/index.d.ts.map +1 -1
- package/dist/go/index.js +1 -1
- package/dist/go/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +13 -10
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +11 -11
- package/dist/internal.js.map +1 -1
- package/dist/lifecycle/engine-ops.d.ts.map +1 -1
- package/dist/lifecycle/engine-ops.js +7 -4
- package/dist/lifecycle/engine-ops.js.map +1 -1
- package/dist/lifecycle/ivtr-loop.d.ts +108 -183
- package/dist/lifecycle/ivtr-loop.d.ts.map +1 -1
- package/dist/lifecycle/ivtr-loop.js +207 -522
- package/dist/lifecycle/ivtr-loop.js.map +1 -1
- package/dist/llm/auxiliary-fallback.js +1 -1
- package/dist/llm/auxiliary-fallback.js.map +1 -1
- package/dist/llm/cli-ops.d.ts +14 -1
- package/dist/llm/cli-ops.d.ts.map +1 -1
- package/dist/llm/cli-ops.js +41 -12
- package/dist/llm/cli-ops.js.map +1 -1
- package/dist/llm/concrete-session.d.ts.map +1 -1
- package/dist/llm/concrete-session.js +4 -0
- package/dist/llm/concrete-session.js.map +1 -1
- package/dist/llm/credentials.d.ts +35 -0
- package/dist/llm/credentials.d.ts.map +1 -1
- package/dist/llm/credentials.js +49 -0
- package/dist/llm/credentials.js.map +1 -1
- package/dist/llm/index.d.ts +4 -0
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +4 -0
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/pi/gondolin-loader.d.ts +241 -0
- package/dist/llm/pi/gondolin-loader.d.ts.map +1 -0
- package/dist/llm/pi/gondolin-loader.js +195 -0
- package/dist/llm/pi/gondolin-loader.js.map +1 -0
- package/dist/llm/pi/index.d.ts +28 -0
- package/dist/llm/pi/index.d.ts.map +1 -0
- package/dist/llm/pi/index.js +27 -0
- package/dist/llm/pi/index.js.map +1 -0
- package/dist/llm/pi/pi-agent-adapter.d.ts +135 -0
- package/dist/llm/pi/pi-agent-adapter.d.ts.map +1 -0
- package/dist/llm/pi/pi-agent-adapter.js +329 -0
- package/dist/llm/pi/pi-agent-adapter.js.map +1 -0
- package/dist/llm/pi/pi-errors.d.ts +161 -0
- package/dist/llm/pi/pi-errors.d.ts.map +1 -0
- package/dist/llm/pi/pi-errors.js +296 -0
- package/dist/llm/pi/pi-errors.js.map +1 -0
- package/dist/llm/pi/pi-execution-env.d.ts +286 -0
- package/dist/llm/pi/pi-execution-env.d.ts.map +1 -0
- package/dist/llm/pi/pi-execution-env.js +406 -0
- package/dist/llm/pi/pi-execution-env.js.map +1 -0
- package/dist/llm/pi/pi-gondolin-env.d.ts +227 -0
- package/dist/llm/pi/pi-gondolin-env.d.ts.map +1 -0
- package/dist/llm/pi/pi-gondolin-env.js +541 -0
- package/dist/llm/pi/pi-gondolin-env.js.map +1 -0
- package/dist/llm/pi/pi-session-storage.d.ts +154 -0
- package/dist/llm/pi/pi-session-storage.d.ts.map +1 -0
- package/dist/llm/pi/pi-session-storage.js +314 -0
- package/dist/llm/pi/pi-session-storage.js.map +1 -0
- package/dist/llm/pi/pi-stream-fn.d.ts +124 -0
- package/dist/llm/pi/pi-stream-fn.d.ts.map +1 -0
- package/dist/llm/pi/pi-stream-fn.js +504 -0
- package/dist/llm/pi/pi-stream-fn.js.map +1 -0
- package/dist/llm/pi/pi-tool-bridge.d.ts +99 -0
- package/dist/llm/pi/pi-tool-bridge.d.ts.map +1 -0
- package/dist/llm/pi/pi-tool-bridge.js +117 -0
- package/dist/llm/pi/pi-tool-bridge.js.map +1 -0
- package/dist/llm/pi/pi-types.d.ts +56 -0
- package/dist/llm/pi/pi-types.d.ts.map +1 -0
- package/dist/llm/pi/pi-types.js +16 -0
- package/dist/llm/pi/pi-types.js.map +1 -0
- package/dist/llm/pi/resolve-execution-env.d.ts +194 -0
- package/dist/llm/pi/resolve-execution-env.d.ts.map +1 -0
- package/dist/llm/pi/resolve-execution-env.js +132 -0
- package/dist/llm/pi/resolve-execution-env.js.map +1 -0
- package/dist/llm/plugin-facade.js +2253 -1151
- package/dist/llm/plugin-facade.js.map +3 -3
- package/dist/llm/role-executor.d.ts.map +1 -1
- package/dist/llm/role-executor.js +8 -5
- package/dist/llm/role-executor.js.map +1 -1
- package/dist/llm/role-resolver.d.ts +46 -14
- package/dist/llm/role-resolver.d.ts.map +1 -1
- package/dist/llm/role-resolver.js +178 -20
- package/dist/llm/role-resolver.js.map +1 -1
- package/dist/llm/sealed-credential.d.ts +125 -0
- package/dist/llm/sealed-credential.d.ts.map +1 -0
- package/dist/llm/sealed-credential.js +133 -0
- package/dist/llm/sealed-credential.js.map +1 -0
- package/dist/llm/session-factory.d.ts.map +1 -1
- package/dist/llm/session-factory.js +6 -2
- package/dist/llm/session-factory.js.map +1 -1
- package/dist/llm/system-key.d.ts +67 -0
- package/dist/llm/system-key.d.ts.map +1 -0
- package/dist/llm/system-key.js +87 -0
- package/dist/llm/system-key.js.map +1 -0
- package/dist/llm/system-of-use-registry.d.ts +119 -0
- package/dist/llm/system-of-use-registry.d.ts.map +1 -0
- package/dist/llm/system-of-use-registry.js +200 -0
- package/dist/llm/system-of-use-registry.js.map +1 -0
- package/dist/llm/system-resolver.d.ts +32 -10
- package/dist/llm/system-resolver.d.ts.map +1 -1
- package/dist/llm/system-resolver.js +70 -18
- package/dist/llm/system-resolver.js.map +1 -1
- package/dist/memory/brain-writer-thread.d.ts.map +1 -1
- package/dist/memory/brain-writer-thread.js +116 -11
- package/dist/memory/brain-writer-thread.js.map +1 -1
- package/dist/memory/claude-mem-migration.d.ts.map +1 -1
- package/dist/memory/claude-mem-migration.js +21 -0
- package/dist/memory/claude-mem-migration.js.map +1 -1
- package/dist/memory/graph-memory-bridge.d.ts.map +1 -1
- package/dist/memory/graph-memory-bridge.js +32 -25
- package/dist/memory/graph-memory-bridge.js.map +1 -1
- package/dist/memory/llm-backend-resolver.js +23 -5
- package/dist/memory/llm-backend-resolver.js.map +1 -1
- package/dist/nexus/migrations/M-split-graph.d.ts.map +1 -1
- package/dist/nexus/migrations/M-split-graph.js +60 -53
- package/dist/nexus/migrations/M-split-graph.js.map +1 -1
- package/dist/orchestrate/pivot.d.ts.map +1 -1
- package/dist/orchestrate/pivot.js +20 -2
- package/dist/orchestrate/pivot.js.map +1 -1
- package/dist/release/engine-ops.js +2 -2
- package/dist/release/engine-ops.js.map +1 -1
- package/dist/routing/capability-matrix.d.ts.map +1 -1
- package/dist/routing/capability-matrix.js +0 -57
- package/dist/routing/capability-matrix.js.map +1 -1
- package/dist/selfimprove/budget.d.ts +206 -0
- package/dist/selfimprove/budget.d.ts.map +1 -0
- package/dist/selfimprove/budget.js +203 -0
- package/dist/selfimprove/budget.js.map +1 -0
- package/dist/selfimprove/dhq-adapter.d.ts +105 -0
- package/dist/selfimprove/dhq-adapter.d.ts.map +1 -0
- package/dist/selfimprove/dhq-adapter.js +95 -0
- package/dist/selfimprove/dhq-adapter.js.map +1 -0
- package/dist/selfimprove/draft-pr.d.ts +129 -0
- package/dist/selfimprove/draft-pr.d.ts.map +1 -0
- package/dist/selfimprove/draft-pr.js +158 -0
- package/dist/selfimprove/draft-pr.js.map +1 -0
- package/dist/selfimprove/envelope-diff.d.ts +162 -0
- package/dist/selfimprove/envelope-diff.d.ts.map +1 -0
- package/dist/selfimprove/envelope-diff.js +321 -0
- package/dist/selfimprove/envelope-diff.js.map +1 -0
- package/dist/selfimprove/replay.d.ts +121 -0
- package/dist/selfimprove/replay.d.ts.map +1 -0
- package/dist/selfimprove/replay.js +109 -0
- package/dist/selfimprove/replay.js.map +1 -0
- package/dist/selfimprove/run-loop.d.ts +148 -0
- package/dist/selfimprove/run-loop.d.ts.map +1 -0
- package/dist/selfimprove/run-loop.js +240 -0
- package/dist/selfimprove/run-loop.js.map +1 -0
- package/dist/selfimprove/scenario.d.ts +145 -0
- package/dist/selfimprove/scenario.d.ts.map +1 -0
- package/dist/selfimprove/scenario.js +243 -0
- package/dist/selfimprove/scenario.js.map +1 -0
- package/dist/sentient/daemon-entry.js +5 -0
- package/dist/sentient/daemon-entry.js.map +1 -1
- package/dist/sentient/daemon.d.ts.map +1 -1
- package/dist/sentient/daemon.js +19 -0
- package/dist/sentient/daemon.js.map +1 -1
- package/dist/sentient/hygiene-scan.d.ts.map +1 -1
- package/dist/sentient/hygiene-scan.js +14 -6
- package/dist/sentient/hygiene-scan.js.map +1 -1
- package/dist/sessions/briefing.d.ts.map +1 -1
- package/dist/sessions/briefing.js +13 -9
- package/dist/sessions/briefing.js.map +1 -1
- package/dist/sessions/connection-session-handle.d.ts +161 -0
- package/dist/sessions/connection-session-handle.d.ts.map +1 -0
- package/dist/sessions/connection-session-handle.js +168 -0
- package/dist/sessions/connection-session-handle.js.map +1 -0
- package/dist/sessions/handoff.d.ts.map +1 -1
- package/dist/sessions/handoff.js +9 -0
- package/dist/sessions/handoff.js.map +1 -1
- package/dist/sessions/index.d.ts +4 -1
- package/dist/sessions/index.d.ts.map +1 -1
- package/dist/sessions/index.js +31 -1
- package/dist/sessions/index.js.map +1 -1
- package/dist/sessions/session-id.d.ts +34 -0
- package/dist/sessions/session-id.d.ts.map +1 -1
- package/dist/sessions/session-id.js +37 -0
- package/dist/sessions/session-id.js.map +1 -1
- package/dist/sessions/session-manifest-mirror.d.ts +115 -0
- package/dist/sessions/session-manifest-mirror.d.ts.map +1 -0
- package/dist/sessions/session-manifest-mirror.js +250 -0
- package/dist/sessions/session-manifest-mirror.js.map +1 -0
- package/dist/sessions/session-switch.d.ts.map +1 -1
- package/dist/sessions/session-switch.js +5 -2
- package/dist/sessions/session-switch.js.map +1 -1
- package/dist/store/converters.d.ts.map +1 -1
- package/dist/store/converters.js +2 -0
- package/dist/store/converters.js.map +1 -1
- package/dist/store/db-helpers.d.ts.map +1 -1
- package/dist/store/db-helpers.js +2 -0
- package/dist/store/db-helpers.js.map +1 -1
- package/dist/store/dual-scope-db.d.ts.map +1 -1
- package/dist/store/dual-scope-db.js +87 -47
- package/dist/store/dual-scope-db.js.map +1 -1
- package/dist/store/pi-session-store.d.ts +151 -0
- package/dist/store/pi-session-store.d.ts.map +1 -0
- package/dist/store/pi-session-store.js +166 -0
- package/dist/store/pi-session-store.js.map +1 -0
- package/dist/store/safety-data-accessor.d.ts +1 -0
- package/dist/store/safety-data-accessor.d.ts.map +1 -1
- package/dist/store/safety-data-accessor.js +5 -0
- package/dist/store/safety-data-accessor.js.map +1 -1
- package/dist/store/schema/cleo-global/accounts.d.ts +357 -0
- package/dist/store/schema/cleo-global/accounts.d.ts.map +1 -0
- package/dist/store/schema/cleo-global/accounts.js +136 -0
- package/dist/store/schema/cleo-global/accounts.js.map +1 -0
- package/dist/store/schema/cleo-global/index.d.ts +2 -0
- package/dist/store/schema/cleo-global/index.d.ts.map +1 -1
- package/dist/store/schema/cleo-global/index.js +2 -0
- package/dist/store/schema/cleo-global/index.js.map +1 -1
- package/dist/store/schema/cleo-global/session-manifest.d.ts +217 -0
- package/dist/store/schema/cleo-global/session-manifest.d.ts.map +1 -0
- package/dist/store/schema/cleo-global/session-manifest.js +99 -0
- package/dist/store/schema/cleo-global/session-manifest.js.map +1 -0
- package/dist/store/schema/cleo-project/tasks-core.d.ts +16 -0
- package/dist/store/schema/cleo-project/tasks-core.d.ts.map +1 -1
- package/dist/store/schema/cleo-project/tasks-core.js +14 -0
- package/dist/store/schema/cleo-project/tasks-core.js.map +1 -1
- package/dist/store/schema/tasks.d.ts +16 -0
- package/dist/store/schema/tasks.d.ts.map +1 -1
- package/dist/store/schema/tasks.js +10 -0
- package/dist/store/schema/tasks.js.map +1 -1
- package/dist/store/selfimprove-dhq-schema.d.ts +284 -0
- package/dist/store/selfimprove-dhq-schema.d.ts.map +1 -0
- package/dist/store/selfimprove-dhq-schema.js +128 -0
- package/dist/store/selfimprove-dhq-schema.js.map +1 -0
- package/dist/store/selfimprove-dhq-store.d.ts +175 -0
- package/dist/store/selfimprove-dhq-store.d.ts.map +1 -0
- package/dist/store/selfimprove-dhq-store.js +182 -0
- package/dist/store/selfimprove-dhq-store.js.map +1 -0
- package/dist/store/session-store.d.ts +52 -13
- package/dist/store/session-store.d.ts.map +1 -1
- package/dist/store/session-store.js +71 -13
- package/dist/store/session-store.js.map +1 -1
- package/dist/store/sqlite-data-accessor.d.ts.map +1 -1
- package/dist/store/sqlite-data-accessor.js +7 -0
- package/dist/store/sqlite-data-accessor.js.map +1 -1
- package/dist/store/umbrella-data-accessor.d.ts +1 -0
- package/dist/store/umbrella-data-accessor.d.ts.map +1 -1
- package/dist/store/umbrella-data-accessor.js +5 -0
- package/dist/store/umbrella-data-accessor.js.map +1 -1
- package/dist/store/validation-schemas.d.ts +32 -0
- package/dist/store/validation-schemas.d.ts.map +1 -1
- package/dist/store/writer-lease-schema.d.ts +392 -0
- package/dist/store/writer-lease-schema.d.ts.map +1 -0
- package/dist/store/writer-lease-schema.js +142 -0
- package/dist/store/writer-lease-schema.js.map +1 -0
- package/dist/store/writer-lease.d.ts +368 -0
- package/dist/store/writer-lease.d.ts.map +1 -0
- package/dist/store/writer-lease.js +1002 -0
- package/dist/store/writer-lease.js.map +1 -0
- package/dist/tasks/backfill-child-projections.d.ts.map +1 -1
- package/dist/tasks/backfill-child-projections.js +14 -9
- package/dist/tasks/backfill-child-projections.js.map +1 -1
- package/dist/tasks/complete.d.ts.map +1 -1
- package/dist/tasks/complete.js +7 -10
- package/dist/tasks/complete.js.map +1 -1
- package/dist/tasks/duplicate-detector.d.ts.map +1 -1
- package/dist/tasks/duplicate-detector.js +14 -7
- package/dist/tasks/duplicate-detector.js.map +1 -1
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +10 -4
- package/dist/telemetry/index.js.map +1 -1
- package/dist/tools/agent-registry.d.ts +250 -0
- package/dist/tools/agent-registry.d.ts.map +1 -0
- package/dist/tools/agent-registry.js +292 -0
- package/dist/tools/agent-registry.js.map +1 -0
- package/dist/tools/agent-tool-families.d.ts +107 -0
- package/dist/tools/agent-tool-families.d.ts.map +1 -0
- package/dist/tools/agent-tool-families.js +527 -0
- package/dist/tools/agent-tool-families.js.map +1 -0
- package/dist/tools/browser-driver.d.ts +183 -0
- package/dist/tools/browser-driver.d.ts.map +1 -0
- package/dist/tools/browser-driver.js +242 -0
- package/dist/tools/browser-driver.js.map +1 -0
- package/dist/tools/builtin-agent-tools.d.ts +36 -0
- package/dist/tools/builtin-agent-tools.d.ts.map +1 -0
- package/dist/tools/builtin-agent-tools.js +150 -0
- package/dist/tools/builtin-agent-tools.js.map +1 -0
- package/dist/tools/dispatch.d.ts +370 -0
- package/dist/tools/dispatch.d.ts.map +1 -0
- package/dist/tools/dispatch.js +505 -0
- package/dist/tools/dispatch.js.map +1 -0
- package/dist/tools/env-scrub.d.ts +93 -0
- package/dist/tools/env-scrub.d.ts.map +1 -0
- package/dist/tools/env-scrub.js +176 -0
- package/dist/tools/env-scrub.js.map +1 -0
- package/dist/tools/fs.d.ts +30 -0
- package/dist/tools/fs.d.ts.map +1 -1
- package/dist/tools/fs.js +55 -2
- package/dist/tools/fs.js.map +1 -1
- package/dist/tools/guard.d.ts +15 -0
- package/dist/tools/guard.d.ts.map +1 -1
- package/dist/tools/guard.js +49 -12
- package/dist/tools/guard.js.map +1 -1
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +37 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/pty.d.ts +45 -0
- package/dist/tools/pty.d.ts.map +1 -0
- package/dist/tools/pty.js +166 -0
- package/dist/tools/pty.js.map +1 -0
- package/dist/tools/schema-gen.d.ts +57 -0
- package/dist/tools/schema-gen.d.ts.map +1 -0
- package/dist/tools/schema-gen.js +52 -0
- package/dist/tools/schema-gen.js.map +1 -0
- package/dist/tools/shell.d.ts +12 -0
- package/dist/tools/shell.d.ts.map +1 -1
- package/dist/tools/shell.js +14 -1
- package/dist/tools/shell.js.map +1 -1
- package/dist/tools/web-agent-tools.d.ts +72 -0
- package/dist/tools/web-agent-tools.d.ts.map +1 -0
- package/dist/tools/web-agent-tools.js +393 -0
- package/dist/tools/web-agent-tools.js.map +1 -0
- package/dist/tools/web-search-backends.d.ts +156 -0
- package/dist/tools/web-search-backends.d.ts.map +1 -0
- package/dist/tools/web-search-backends.js +290 -0
- package/dist/tools/web-search-backends.js.map +1 -0
- package/dist/validation/ops.d.ts +1 -15
- package/dist/validation/ops.d.ts.map +1 -1
- package/dist/validation/ops.js +0 -20
- package/dist/validation/ops.js.map +1 -1
- package/migrations/drizzle-cleo-global/20260607000000_t11891-writer-leases/migration.sql +55 -0
- package/migrations/drizzle-cleo-global/20260607010000_t11639-session-manifest/migration.sql +43 -0
- package/migrations/drizzle-cleo-global/20260608000000_t11899-pi-session-tree/migration.sql +52 -0
- package/migrations/drizzle-cleo-global/20260608010000_t11709-accounts-credential-pool/migration.sql +72 -0
- package/migrations/drizzle-cleo-global/20260608020000_t11889-selfimprove-dhq/migration.sql +64 -0
- package/migrations/drizzle-cleo-project/20260607000000_t11891-writer-leases/migration.sql +55 -0
- package/migrations/drizzle-cleo-project/20260607010000_t11639-session-parent/migration.sql +22 -0
- package/migrations/drizzle-cleo-project/20260608000000_t11899-pi-session-tree/migration.sql +52 -0
- package/migrations/drizzle-cleo-project/20260608020000_t11889-selfimprove-dhq/migration.sql +64 -0
- package/package.json +15 -13
- package/dist/lifecycle/chain-composition.d.ts +0 -30
- package/dist/lifecycle/chain-composition.d.ts.map +0 -1
- package/dist/lifecycle/chain-composition.js +0 -152
- package/dist/lifecycle/chain-composition.js.map +0 -1
- package/dist/lifecycle/chain-store.d.ts +0 -70
- package/dist/lifecycle/chain-store.d.ts.map +0 -1
- package/dist/lifecycle/chain-store.js +0 -246
- package/dist/lifecycle/chain-store.js.map +0 -1
- package/dist/lifecycle/default-chain.d.ts +0 -39
- package/dist/lifecycle/default-chain.d.ts.map +0 -1
- package/dist/lifecycle/default-chain.js +0 -176
- package/dist/lifecycle/default-chain.js.map +0 -1
- package/dist/lifecycle/tessera-engine.d.ts +0 -48
- package/dist/lifecycle/tessera-engine.d.ts.map +0 -1
- package/dist/lifecycle/tessera-engine.js +0 -249
- package/dist/lifecycle/tessera-engine.js.map +0 -1
- package/dist/validation/chain-validation.d.ts +0 -43
- package/dist/validation/chain-validation.d.ts.map +0 -1
- package/dist/validation/chain-validation.js +0 -146
- package/dist/validation/chain-validation.js.map +0 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-improvement scenario replay via an injected dispatch port (T11889-B).
|
|
3
|
+
*
|
|
4
|
+
* `replayScenario` replays a scenario's ordered ops through an injected
|
|
5
|
+
* {@link ReplayDispatch} port — it captures ONE LAFS envelope per op. CORE owns
|
|
6
|
+
* the PORT TYPE only; the real adapter (a thin closure over the cleo-resident
|
|
7
|
+
* `Dispatcher`) is supplied by `packages/cleo` at the call site (dependency
|
|
8
|
+
* inversion — `core` MUST NOT import the cleo dispatcher, and `dispatchFromCore`
|
|
9
|
+
* does not exist; see the P5 self-improvement spec §B.0.1).
|
|
10
|
+
*
|
|
11
|
+
* This module is PURE — no DB, no native handle, no `cleo` mutation. Tests inject
|
|
12
|
+
* a mocked `ReplayDispatch`. Import-time side-effect-free: the logger is resolved
|
|
13
|
+
* lazily on first use.
|
|
14
|
+
*
|
|
15
|
+
* Read-only guarantee: in the in-process fallback (no VM isolation) a `mutate` op
|
|
16
|
+
* could touch a live handle, so {@link replayScenario} HARD-REJECTS any
|
|
17
|
+
* `gateway:'mutate'` op when `allowMutate` is not explicitly set, throwing
|
|
18
|
+
* {@link MutateInFallbackError} (code `E_SELFIMPROVE_MUTATE_IN_FALLBACK`). The
|
|
19
|
+
* canned dogfood scenario is `query`-only, so the default replay never mutates.
|
|
20
|
+
*
|
|
21
|
+
* @module @cleocode/core/selfimprove/replay
|
|
22
|
+
* @epic T11889
|
|
23
|
+
* @task T11912
|
|
24
|
+
*/
|
|
25
|
+
import type { DispatchResponse } from '@cleocode/contracts/gateway';
|
|
26
|
+
import type { Scenario, ScenarioOp } from './scenario.js';
|
|
27
|
+
/**
|
|
28
|
+
* The captured envelope shape per replayed op.
|
|
29
|
+
*
|
|
30
|
+
* This is the canonical {@link DispatchResponse} the cleo-side `Dispatcher`
|
|
31
|
+
* returns (a `meta` block + `success` + optional `data`/`error`/`page`/`partial`).
|
|
32
|
+
* The diff layer (see {@link "./envelope-diff.js"}) normalizes this by stripping
|
|
33
|
+
* the volatile `meta` fields before comparing against the golden.
|
|
34
|
+
*/
|
|
35
|
+
export type ReplayEnvelope = DispatchResponse;
|
|
36
|
+
/**
|
|
37
|
+
* Narrow dispatch port the replay engine calls — CORE owns this TYPE, NOT the impl.
|
|
38
|
+
*
|
|
39
|
+
* The cleo dispatch handler supplies the concrete adapter by closing over its
|
|
40
|
+
* already-instantiated `Dispatcher` (`dispatcher.dispatch({ gateway, domain,
|
|
41
|
+
* operation, params, source, requestId })`, where `source` is a valid
|
|
42
|
+
* `GatewaySource` — e.g. `'rpc'`) and returning the resulting envelope. Injecting
|
|
43
|
+
* the port keeps the engine + diff + budget logic
|
|
44
|
+
* in `core` while the dispatcher binding lives in `cleo` (CORE-first, no
|
|
45
|
+
* package-boundary inversion).
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* The dispatch coordinate handed to a {@link ReplayDispatch} port for one op.
|
|
49
|
+
*/
|
|
50
|
+
export interface ReplayDispatchOp {
|
|
51
|
+
/** CQRS gateway. */
|
|
52
|
+
gateway: ScenarioOp['gateway'];
|
|
53
|
+
/** Registered domain handler key (plural, e.g. `'tasks'`). */
|
|
54
|
+
domain: string;
|
|
55
|
+
/** Operation name within the domain. */
|
|
56
|
+
operation: string;
|
|
57
|
+
/** Optional operation parameters. */
|
|
58
|
+
params?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Dispatch a single op and return its captured envelope.
|
|
62
|
+
*
|
|
63
|
+
* @param op - The dispatch coordinate (gateway, domain, operation, params).
|
|
64
|
+
* @returns The captured {@link ReplayEnvelope}.
|
|
65
|
+
*/
|
|
66
|
+
export type ReplayDispatch = (op: ReplayDispatchOp) => Promise<ReplayEnvelope>;
|
|
67
|
+
/** Options controlling a replay run. */
|
|
68
|
+
export interface ReplayOptions {
|
|
69
|
+
/**
|
|
70
|
+
* When `true`, permit `gateway:'mutate'` ops (VM-isolated execution path).
|
|
71
|
+
*
|
|
72
|
+
* Defaults to `false`: in the in-process fallback there is no VM boundary, so a
|
|
73
|
+
* mutate op is HARD-REJECTED with {@link MutateInFallbackError}. The canned
|
|
74
|
+
* dogfood scenario is `query`-only and never sets this.
|
|
75
|
+
*
|
|
76
|
+
* @defaultValue false
|
|
77
|
+
*/
|
|
78
|
+
allowMutate?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Thrown when a `gateway:'mutate'` op is replayed without `allowMutate`.
|
|
82
|
+
*
|
|
83
|
+
* In the in-process fallback the replay runs in the host process, which DOES hold
|
|
84
|
+
* live-DB handles; a mutate op there could corrupt a live `tasks.db`/`brain.db`
|
|
85
|
+
* (the T5158 vector). The hard guard ensures no mutate path can fire without an
|
|
86
|
+
* explicit VM-isolation opt-in.
|
|
87
|
+
*/
|
|
88
|
+
export declare class MutateInFallbackError extends Error {
|
|
89
|
+
/** Stable machine-readable error code. */
|
|
90
|
+
readonly code: "E_SELFIMPROVE_MUTATE_IN_FALLBACK";
|
|
91
|
+
/** The op coordinate (`domain.operation`) that was rejected. */
|
|
92
|
+
readonly opCoord: string;
|
|
93
|
+
/**
|
|
94
|
+
* @param op - The rejected mutate op.
|
|
95
|
+
*/
|
|
96
|
+
constructor(op: ScenarioOp);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Replay a scenario's ordered ops through the injected dispatch port.
|
|
100
|
+
*
|
|
101
|
+
* Captures ONE envelope per op, in op order. Read-only by default: every
|
|
102
|
+
* `gateway:'mutate'` op is HARD-REJECTED with {@link MutateInFallbackError}
|
|
103
|
+
* unless `options.allowMutate` is set (the VM-isolation path).
|
|
104
|
+
*
|
|
105
|
+
* PURE — no DB, no mutation. The `dispatch` port is the only external dependency;
|
|
106
|
+
* tests inject a mock.
|
|
107
|
+
*
|
|
108
|
+
* @param scenario - The validated scenario whose ops are replayed.
|
|
109
|
+
* @param dispatch - The injected dispatch port (cleo supplies the real adapter).
|
|
110
|
+
* @param options - Replay options; see {@link ReplayOptions}.
|
|
111
|
+
* @returns The captured envelopes, one per op, in scenario order.
|
|
112
|
+
* @throws {@link MutateInFallbackError} On a `mutate` op without `allowMutate`.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const envelopes = await replayScenario(scenario, dispatch);
|
|
117
|
+
* // envelopes.length === scenario.ops.length
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function replayScenario(scenario: Scenario, dispatch: ReplayDispatch, options?: ReplayOptions): Promise<ReplayEnvelope[]>;
|
|
121
|
+
//# sourceMappingURL=replay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/selfimprove/replay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAE9C;;;;;;;;;;GAUG;AACH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oBAAoB;IACpB,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IAC/B,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,EAAE,EAAE,gBAAgB,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;AAE/E,wCAAwC;AACxC,MAAM,WAAW,aAAa;IAC5B;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,0CAA0C;IAC1C,SAAgB,IAAI,EAAG,kCAAkC,CAAU;IAEnE,gEAAgE;IAChE,SAAgB,OAAO,EAAE,MAAM,CAAC;IAEhC;;OAEG;gBACS,EAAE,EAAE,UAAU;CAS3B;AAuBD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,cAAc,EACxB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,EAAE,CAAC,CAwB3B"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-improvement scenario replay via an injected dispatch port (T11889-B).
|
|
3
|
+
*
|
|
4
|
+
* `replayScenario` replays a scenario's ordered ops through an injected
|
|
5
|
+
* {@link ReplayDispatch} port — it captures ONE LAFS envelope per op. CORE owns
|
|
6
|
+
* the PORT TYPE only; the real adapter (a thin closure over the cleo-resident
|
|
7
|
+
* `Dispatcher`) is supplied by `packages/cleo` at the call site (dependency
|
|
8
|
+
* inversion — `core` MUST NOT import the cleo dispatcher, and `dispatchFromCore`
|
|
9
|
+
* does not exist; see the P5 self-improvement spec §B.0.1).
|
|
10
|
+
*
|
|
11
|
+
* This module is PURE — no DB, no native handle, no `cleo` mutation. Tests inject
|
|
12
|
+
* a mocked `ReplayDispatch`. Import-time side-effect-free: the logger is resolved
|
|
13
|
+
* lazily on first use.
|
|
14
|
+
*
|
|
15
|
+
* Read-only guarantee: in the in-process fallback (no VM isolation) a `mutate` op
|
|
16
|
+
* could touch a live handle, so {@link replayScenario} HARD-REJECTS any
|
|
17
|
+
* `gateway:'mutate'` op when `allowMutate` is not explicitly set, throwing
|
|
18
|
+
* {@link MutateInFallbackError} (code `E_SELFIMPROVE_MUTATE_IN_FALLBACK`). The
|
|
19
|
+
* canned dogfood scenario is `query`-only, so the default replay never mutates.
|
|
20
|
+
*
|
|
21
|
+
* @module @cleocode/core/selfimprove/replay
|
|
22
|
+
* @epic T11889
|
|
23
|
+
* @task T11912
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Thrown when a `gateway:'mutate'` op is replayed without `allowMutate`.
|
|
27
|
+
*
|
|
28
|
+
* In the in-process fallback the replay runs in the host process, which DOES hold
|
|
29
|
+
* live-DB handles; a mutate op there could corrupt a live `tasks.db`/`brain.db`
|
|
30
|
+
* (the T5158 vector). The hard guard ensures no mutate path can fire without an
|
|
31
|
+
* explicit VM-isolation opt-in.
|
|
32
|
+
*/
|
|
33
|
+
export class MutateInFallbackError extends Error {
|
|
34
|
+
/** Stable machine-readable error code. */
|
|
35
|
+
code = 'E_SELFIMPROVE_MUTATE_IN_FALLBACK';
|
|
36
|
+
/** The op coordinate (`domain.operation`) that was rejected. */
|
|
37
|
+
opCoord;
|
|
38
|
+
/**
|
|
39
|
+
* @param op - The rejected mutate op.
|
|
40
|
+
*/
|
|
41
|
+
constructor(op) {
|
|
42
|
+
const opCoord = `${op.domain}.${op.operation}`;
|
|
43
|
+
super(`Refusing to replay mutate op '${opCoord}' without VM isolation ` +
|
|
44
|
+
'(set allowMutate only when running in a sandbox VM)');
|
|
45
|
+
this.name = 'MutateInFallbackError';
|
|
46
|
+
this.opCoord = opCoord;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Lazily-resolved module logger.
|
|
51
|
+
*
|
|
52
|
+
* Resolved on first use rather than at import time so importing this module never
|
|
53
|
+
* triggers logger initialization. The cached instance is reused across calls.
|
|
54
|
+
*/
|
|
55
|
+
let cachedLogger;
|
|
56
|
+
/**
|
|
57
|
+
* Resolve the module logger, initializing it lazily on first call.
|
|
58
|
+
*
|
|
59
|
+
* @returns The `selfimprove-replay` subsystem logger.
|
|
60
|
+
*/
|
|
61
|
+
async function getModuleLogger() {
|
|
62
|
+
if (cachedLogger === undefined) {
|
|
63
|
+
const { getLogger } = await import('../logger.js');
|
|
64
|
+
cachedLogger = getLogger('selfimprove-replay');
|
|
65
|
+
}
|
|
66
|
+
return cachedLogger;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Replay a scenario's ordered ops through the injected dispatch port.
|
|
70
|
+
*
|
|
71
|
+
* Captures ONE envelope per op, in op order. Read-only by default: every
|
|
72
|
+
* `gateway:'mutate'` op is HARD-REJECTED with {@link MutateInFallbackError}
|
|
73
|
+
* unless `options.allowMutate` is set (the VM-isolation path).
|
|
74
|
+
*
|
|
75
|
+
* PURE — no DB, no mutation. The `dispatch` port is the only external dependency;
|
|
76
|
+
* tests inject a mock.
|
|
77
|
+
*
|
|
78
|
+
* @param scenario - The validated scenario whose ops are replayed.
|
|
79
|
+
* @param dispatch - The injected dispatch port (cleo supplies the real adapter).
|
|
80
|
+
* @param options - Replay options; see {@link ReplayOptions}.
|
|
81
|
+
* @returns The captured envelopes, one per op, in scenario order.
|
|
82
|
+
* @throws {@link MutateInFallbackError} On a `mutate` op without `allowMutate`.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const envelopes = await replayScenario(scenario, dispatch);
|
|
87
|
+
* // envelopes.length === scenario.ops.length
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export async function replayScenario(scenario, dispatch, options = {}) {
|
|
91
|
+
const allowMutate = options.allowMutate ?? false;
|
|
92
|
+
const logger = await getModuleLogger();
|
|
93
|
+
const captured = [];
|
|
94
|
+
for (const op of scenario.ops) {
|
|
95
|
+
if (op.gateway === 'mutate' && !allowMutate) {
|
|
96
|
+
throw new MutateInFallbackError(op);
|
|
97
|
+
}
|
|
98
|
+
const envelope = await dispatch({
|
|
99
|
+
gateway: op.gateway,
|
|
100
|
+
domain: op.domain,
|
|
101
|
+
operation: op.operation,
|
|
102
|
+
...(op.params !== undefined ? { params: op.params } : {}),
|
|
103
|
+
});
|
|
104
|
+
captured.push(envelope);
|
|
105
|
+
}
|
|
106
|
+
logger.debug({ scenario: scenario.name, captured: captured.length }, 'replayed self-improvement scenario');
|
|
107
|
+
return captured;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=replay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.js","sourceRoot":"","sources":["../../src/selfimprove/replay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AA+DH;;;;;;;GAOG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,0CAA0C;IAC1B,IAAI,GAAG,kCAA2C,CAAC;IAEnE,gEAAgE;IAChD,OAAO,CAAS;IAEhC;;OAEG;IACH,YAAY,EAAc;QACxB,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,IAAI,EAAE,CAAC,SAAS,EAAE,CAAC;QAC/C,KAAK,CACH,iCAAiC,OAAO,yBAAyB;YAC/D,qDAAqD,CACxD,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAED;;;;;GAKG;AACH,IAAI,YAAgC,CAAC;AAErC;;;;GAIG;AACH,KAAK,UAAU,eAAe;IAC5B,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;QACnD,YAAY,GAAG,SAAS,CAAC,oBAAoB,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,QAAkB,EAClB,QAAwB,EACxB,UAAyB,EAAE;IAE3B,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,KAAK,CAAC;IACjD,MAAM,MAAM,GAAG,MAAM,eAAe,EAAE,CAAC;IAEvC,MAAM,QAAQ,GAAqB,EAAE,CAAC;IACtC,KAAK,MAAM,EAAE,IAAI,QAAQ,CAAC,GAAG,EAAE,CAAC;QAC9B,IAAI,EAAE,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,WAAW,EAAE,CAAC;YAC5C,MAAM,IAAI,qBAAqB,CAAC,EAAE,CAAC,CAAC;QACtC,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC;YAC9B,OAAO,EAAE,EAAE,CAAC,OAAO;YACnB,MAAM,EAAE,EAAE,CAAC,MAAM;YACjB,SAAS,EAAE,EAAE,CAAC,SAAS;YACvB,GAAG,CAAC,EAAE,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1D,CAAC,CAAC;QACH,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,KAAK,CACV,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,EACtD,oCAAoC,CACrC,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-improvement loop engine entry (T11889 · T11889-C).
|
|
3
|
+
*
|
|
4
|
+
* {@link runSelfImprove} is the CORE engine the thin `cleo selfimprove run` CLI
|
|
5
|
+
* verb delegates to. It orchestrates the full walking skeleton:
|
|
6
|
+
*
|
|
7
|
+
* 1. **boot ONE sandbox** via
|
|
8
|
+
* {@link "../llm/pi/resolve-execution-env.js".resolveExecutionEnv} (prefers the
|
|
9
|
+
* Gondolin micro-VM; degrades to the in-process `GuardedExecutionEnv` in CI) —
|
|
10
|
+
* counted against the `maxWorktrees = 1` budget;
|
|
11
|
+
* 2. **replay** the canned scenario in-process via the injected
|
|
12
|
+
* {@link "./replay.js".ReplayDispatch} port (the cleo handler supplies the real
|
|
13
|
+
* adapter; the default scenario is `query`-only so the replay never mutates);
|
|
14
|
+
* 3. **diff** the captured envelopes vs the golden
|
|
15
|
+
* ({@link "./envelope-diff.js".diffEnvelopes}) — zero regressions ⇒ a SILENT,
|
|
16
|
+
* no-write green run;
|
|
17
|
+
* 4. on a regression, **emit ONE DHQ** row via the leased
|
|
18
|
+
* {@link "./dhq-adapter.js".DhqAdapter} (UPSERT under
|
|
19
|
+
* `withWriterLease('project','bulk',…)`) — ONLY when `execute` is set;
|
|
20
|
+
* 5. **open ONE DRAFT PR** ({@link "./draft-pr.js".openDraftPr}, dry-run unless
|
|
21
|
+
* `execute`) and record its URL back on the DHQ row.
|
|
22
|
+
*
|
|
23
|
+
* Self-dogfooding guardrails (NON-NEGOTIABLE, P5 spec §B.7):
|
|
24
|
+
* - **Default OFF.** Mutation + egress require `opts.execute === true`. Without
|
|
25
|
+
* it the loop runs DRY-RUN: replay + diff + report, NO DB write, NO PR.
|
|
26
|
+
* - **Circuit-breaker** ({@link "./budget.js".CircuitBreaker}) HALTS the run on
|
|
27
|
+
* gate-RED, a `require`-mode lease throw (`LeaseUnavailableError`), budget
|
|
28
|
+
* overrun, or a DB error from the leased section. It does NOT trip on
|
|
29
|
+
* "daemon OFF" (the normal `local`-mode state).
|
|
30
|
+
* - **Budget caps** (in-code): `maxTokens` / `maxUsd` / `maxPrs = 1` /
|
|
31
|
+
* `maxWorktrees = 1`, checked PRE-FLIGHT before each costed step. `MemoryMax=32G`
|
|
32
|
+
* is an operational launch-wrapper, not an in-code cap.
|
|
33
|
+
* - **NO autonomous fix-gen, NO auto-merge, NO end-user mode in v1.** The loop
|
|
34
|
+
* surfaces regressions as DHQs + draft PRs; a human drives the fix.
|
|
35
|
+
*
|
|
36
|
+
* CORE-first: this engine lives in `core` and owns the `ReplayDispatch` port TYPE;
|
|
37
|
+
* the cleo dispatch handler supplies the concrete adapter (dependency inversion —
|
|
38
|
+
* `core` never imports the cleo-resident dispatcher). Import-time side-effect-free.
|
|
39
|
+
*
|
|
40
|
+
* @module @cleocode/core/selfimprove/run-loop
|
|
41
|
+
* @epic T11889
|
|
42
|
+
* @task T11913
|
|
43
|
+
*/
|
|
44
|
+
import { type ExecutionEnvBackend } from '../llm/pi/resolve-execution-env.js';
|
|
45
|
+
import { type ToolGuard } from '../tools/guard.js';
|
|
46
|
+
import { type CircuitBreakerState, DEFAULT_BUDGET, type SelfImproveBudget } from './budget.js';
|
|
47
|
+
import { type DhqAdapter } from './dhq-adapter.js';
|
|
48
|
+
import { type DraftPrResult } from './draft-pr.js';
|
|
49
|
+
import { type DiffEntry } from './envelope-diff.js';
|
|
50
|
+
import { type ReplayDispatch } from './replay.js';
|
|
51
|
+
/** Options for {@link runSelfImprove}. */
|
|
52
|
+
export interface RunSelfImproveOptions {
|
|
53
|
+
/** The canned scenario name to replay (e.g. `'dhq-replay-find'`). */
|
|
54
|
+
readonly scenario: string;
|
|
55
|
+
/**
|
|
56
|
+
* The injected dispatch port — the cleo handler supplies a closure over its
|
|
57
|
+
* `Dispatcher`. CORE owns the TYPE; the impl is injected (dependency inversion).
|
|
58
|
+
*/
|
|
59
|
+
readonly dispatch: ReplayDispatch;
|
|
60
|
+
/**
|
|
61
|
+
* When `true`, PERMIT mutation (the leased DHQ UPSERT) + egress (the draft PR).
|
|
62
|
+
* DEFAULT `false`: the loop runs DRY-RUN (replay + diff + report only). This is
|
|
63
|
+
* the hard default-OFF gate — nothing is written or pushed without it.
|
|
64
|
+
*
|
|
65
|
+
* @defaultValue false
|
|
66
|
+
*/
|
|
67
|
+
readonly execute?: boolean;
|
|
68
|
+
/** Project working directory for scope resolution + the fallback workspace root. */
|
|
69
|
+
readonly cwd?: string;
|
|
70
|
+
/**
|
|
71
|
+
* The confinement backend the run prefers. Defaults to `'gondolin'` (degrades to
|
|
72
|
+
* the in-process guarded env when the VM infra is absent — the CI path).
|
|
73
|
+
*
|
|
74
|
+
* @defaultValue 'gondolin'
|
|
75
|
+
*/
|
|
76
|
+
readonly backend?: ExecutionEnvBackend;
|
|
77
|
+
/** Disposable seeded-copy mount dir for a booted VM (never the live DBs). */
|
|
78
|
+
readonly seededCopyDir?: string;
|
|
79
|
+
/** Optional explicit budget overrides (PRs/worktrees always clamped to 1). */
|
|
80
|
+
readonly budget?: Partial<SelfImproveBudget>;
|
|
81
|
+
/**
|
|
82
|
+
* A pre-flight architectural-gate signal. When this resolves `true` the
|
|
83
|
+
* circuit-breaker trips with `gateRed` BEFORE any persist/egress (never propose
|
|
84
|
+
* a fix that itself regresses a gate). Injected so the engine stays pure of the
|
|
85
|
+
* `cleo check arch` shell-out (the cleo handler supplies it); omitted ⇒ assumed green.
|
|
86
|
+
*/
|
|
87
|
+
readonly gateRedCheck?: () => Promise<boolean>;
|
|
88
|
+
/** Test seam: inject a DHQ adapter (defaults to the real leased adapter). */
|
|
89
|
+
readonly adapter?: DhqAdapter;
|
|
90
|
+
/** Test seam: inject the guard backing the in-process fallback env. */
|
|
91
|
+
readonly guard?: ToolGuard;
|
|
92
|
+
/** Test seam: inject the run id (defaults to a timestamped id). */
|
|
93
|
+
readonly runId?: string;
|
|
94
|
+
/** Test seam: inject a clock (defaults to {@link Date.now}). */
|
|
95
|
+
readonly now?: () => number;
|
|
96
|
+
}
|
|
97
|
+
/** The terminal status of a self-improvement run. */
|
|
98
|
+
export type RunOutcome =
|
|
99
|
+
/** Replay matched the golden — no regression, no DHQ, no PR. */
|
|
100
|
+
'green'
|
|
101
|
+
/** Regression found; in dry-run mode (no write / no PR). */
|
|
102
|
+
| 'regression-dry-run'
|
|
103
|
+
/** Regression found; DHQ written + draft PR opened (execute mode). */
|
|
104
|
+
| 'regression-acted'
|
|
105
|
+
/** The circuit-breaker halted the run. */
|
|
106
|
+
| 'halted';
|
|
107
|
+
/** The structured result of one {@link runSelfImprove} call. */
|
|
108
|
+
export interface SelfImproveResult {
|
|
109
|
+
/** The terminal outcome. */
|
|
110
|
+
readonly outcome: RunOutcome;
|
|
111
|
+
/** The scenario replayed. */
|
|
112
|
+
readonly scenario: string;
|
|
113
|
+
/** The run id (ties any DHQ row to this run). */
|
|
114
|
+
readonly runId: string;
|
|
115
|
+
/** Whether mutation/egress was permitted (`execute`). */
|
|
116
|
+
readonly executed: boolean;
|
|
117
|
+
/** The detected regressions (empty on a green run). */
|
|
118
|
+
readonly regressions: readonly DiffEntry[];
|
|
119
|
+
/** The idempotency `question_hash` for the regression set, or `null` when green. */
|
|
120
|
+
readonly questionHash: string | null;
|
|
121
|
+
/** The draft-PR egress result, or `null` when none fired (green / dry-run-no-egress). */
|
|
122
|
+
readonly draftPr: DraftPrResult | null;
|
|
123
|
+
/** The final circuit-breaker state. */
|
|
124
|
+
readonly breaker: CircuitBreakerState;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Run ONE self-improvement loop iteration.
|
|
128
|
+
*
|
|
129
|
+
* Boots one sandbox, replays the scenario, diffs vs the golden, and — ONLY when
|
|
130
|
+
* `opts.execute` is set AND a regression is found AND the circuit-breaker is closed —
|
|
131
|
+
* emits one leased DHQ row and opens one draft PR. Honors the budget caps and the
|
|
132
|
+
* circuit-breaker throughout (a tripped breaker short-circuits persist + egress to
|
|
133
|
+
* a no-op report).
|
|
134
|
+
*
|
|
135
|
+
* @param opts - See {@link RunSelfImproveOptions}.
|
|
136
|
+
* @returns The structured {@link SelfImproveResult}.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* // dry-run (default): replay + diff + report, no write, no PR
|
|
141
|
+
* const res = await runSelfImprove({ scenario: 'dhq-replay-find', dispatch });
|
|
142
|
+
* // execute: write a leased DHQ + open ONE draft PR on regression
|
|
143
|
+
* const acted = await runSelfImprove({ scenario: 'dhq-replay-find', dispatch, execute: true });
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export declare function runSelfImprove(opts: RunSelfImproveOptions): Promise<SelfImproveResult>;
|
|
147
|
+
export { DEFAULT_BUDGET };
|
|
148
|
+
//# sourceMapping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
3
|
+
*
|
|
4
|
+
* {@link runSelfImprove} is the CORE engine the thin `cleo selfimprove run` CLI
|
|
5
|
+
* verb delegates to. It orchestrates the full walking skeleton:
|
|
6
|
+
*
|
|
7
|
+
* 1. **boot ONE sandbox** via
|
|
8
|
+
* {@link "../llm/pi/resolve-execution-env.js".resolveExecutionEnv} (prefers the
|
|
9
|
+
* Gondolin micro-VM; degrades to the in-process `GuardedExecutionEnv` in CI) —
|
|
10
|
+
* counted against the `maxWorktrees = 1` budget;
|
|
11
|
+
* 2. **replay** the canned scenario in-process via the injected
|
|
12
|
+
* {@link "./replay.js".ReplayDispatch} port (the cleo handler supplies the real
|
|
13
|
+
* adapter; the default scenario is `query`-only so the replay never mutates);
|
|
14
|
+
* 3. **diff** the captured envelopes vs the golden
|
|
15
|
+
* ({@link "./envelope-diff.js".diffEnvelopes}) — zero regressions ⇒ a SILENT,
|
|
16
|
+
* no-write green run;
|
|
17
|
+
* 4. on a regression, **emit ONE DHQ** row via the leased
|
|
18
|
+
* {@link "./dhq-adapter.js".DhqAdapter} (UPSERT under
|
|
19
|
+
* `withWriterLease('project','bulk',…)`) — ONLY when `execute` is set;
|
|
20
|
+
* 5. **open ONE DRAFT PR** ({@link "./draft-pr.js".openDraftPr}, dry-run unless
|
|
21
|
+
* `execute`) and record its URL back on the DHQ row.
|
|
22
|
+
*
|
|
23
|
+
* Self-dogfooding guardrails (NON-NEGOTIABLE, P5 spec §B.7):
|
|
24
|
+
* - **Default OFF.** Mutation + egress require `opts.execute === true`. Without
|
|
25
|
+
* it the loop runs DRY-RUN: replay + diff + report, NO DB write, NO PR.
|
|
26
|
+
* - **Circuit-breaker** ({@link "./budget.js".CircuitBreaker}) HALTS the run on
|
|
27
|
+
* gate-RED, a `require`-mode lease throw (`LeaseUnavailableError`), budget
|
|
28
|
+
* overrun, or a DB error from the leased section. It does NOT trip on
|
|
29
|
+
* "daemon OFF" (the normal `local`-mode state).
|
|
30
|
+
* - **Budget caps** (in-code): `maxTokens` / `maxUsd` / `maxPrs = 1` /
|
|
31
|
+
* `maxWorktrees = 1`, checked PRE-FLIGHT before each costed step. `MemoryMax=32G`
|
|
32
|
+
* is an operational launch-wrapper, not an in-code cap.
|
|
33
|
+
* - **NO autonomous fix-gen, NO auto-merge, NO end-user mode in v1.** The loop
|
|
34
|
+
* surfaces regressions as DHQs + draft PRs; a human drives the fix.
|
|
35
|
+
*
|
|
36
|
+
* CORE-first: this engine lives in `core` and owns the `ReplayDispatch` port TYPE;
|
|
37
|
+
* the cleo dispatch handler supplies the concrete adapter (dependency inversion —
|
|
38
|
+
* `core` never imports the cleo-resident dispatcher). Import-time side-effect-free.
|
|
39
|
+
*
|
|
40
|
+
* @module @cleocode/core/selfimprove/run-loop
|
|
41
|
+
* @epic T11889
|
|
42
|
+
* @task T11913
|
|
43
|
+
*/
|
|
44
|
+
import { resolveExecutionEnv } from '../llm/pi/resolve-execution-env.js';
|
|
45
|
+
import { resolveOrCwd } from '../paths.js';
|
|
46
|
+
import { LeaseUnavailableError } from '../store/writer-lease.js';
|
|
47
|
+
import { createToolGuard } from '../tools/guard.js';
|
|
48
|
+
import { CircuitBreaker, DEFAULT_BUDGET, resolveBudget, } from './budget.js';
|
|
49
|
+
import { createDhqAdapter } from './dhq-adapter.js';
|
|
50
|
+
import { openDraftPr } from './draft-pr.js';
|
|
51
|
+
import { computeQuestionHash, diffEnvelopes } from './envelope-diff.js';
|
|
52
|
+
import { replayScenario } from './replay.js';
|
|
53
|
+
import { loadScenario } from './scenario.js';
|
|
54
|
+
/**
|
|
55
|
+
* Lazily-resolved module logger (import-time side-effect-free).
|
|
56
|
+
*/
|
|
57
|
+
let cachedLogger;
|
|
58
|
+
async function getModuleLogger() {
|
|
59
|
+
if (cachedLogger === undefined) {
|
|
60
|
+
const { getLogger } = await import('../logger.js');
|
|
61
|
+
cachedLogger = getLogger('selfimprove-run-loop');
|
|
62
|
+
}
|
|
63
|
+
return cachedLogger;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Run ONE self-improvement loop iteration.
|
|
67
|
+
*
|
|
68
|
+
* Boots one sandbox, replays the scenario, diffs vs the golden, and — ONLY when
|
|
69
|
+
* `opts.execute` is set AND a regression is found AND the circuit-breaker is closed —
|
|
70
|
+
* emits one leased DHQ row and opens one draft PR. Honors the budget caps and the
|
|
71
|
+
* circuit-breaker throughout (a tripped breaker short-circuits persist + egress to
|
|
72
|
+
* a no-op report).
|
|
73
|
+
*
|
|
74
|
+
* @param opts - See {@link RunSelfImproveOptions}.
|
|
75
|
+
* @returns The structured {@link SelfImproveResult}.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* // dry-run (default): replay + diff + report, no write, no PR
|
|
80
|
+
* const res = await runSelfImprove({ scenario: 'dhq-replay-find', dispatch });
|
|
81
|
+
* // execute: write a leased DHQ + open ONE draft PR on regression
|
|
82
|
+
* const acted = await runSelfImprove({ scenario: 'dhq-replay-find', dispatch, execute: true });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export async function runSelfImprove(opts) {
|
|
86
|
+
const logger = await getModuleLogger();
|
|
87
|
+
const execute = opts.execute === true;
|
|
88
|
+
const backend = opts.backend ?? 'gondolin';
|
|
89
|
+
const now = opts.now ?? (() => Date.now());
|
|
90
|
+
const runId = opts.runId ?? `selfimprove-${now()}`;
|
|
91
|
+
const budget = resolveBudget(opts.budget ?? {});
|
|
92
|
+
const breaker = new CircuitBreaker(budget);
|
|
93
|
+
const adapter = opts.adapter ?? createDhqAdapter({ cwd: opts.cwd, now });
|
|
94
|
+
const halted = (scenario, regressions, questionHash) => ({
|
|
95
|
+
outcome: 'halted',
|
|
96
|
+
scenario,
|
|
97
|
+
runId,
|
|
98
|
+
executed: execute,
|
|
99
|
+
regressions,
|
|
100
|
+
questionHash,
|
|
101
|
+
draftPr: null,
|
|
102
|
+
breaker: breaker.state,
|
|
103
|
+
});
|
|
104
|
+
// ── 1. boot ONE sandbox (counts against maxWorktrees=1) ─────────────────────
|
|
105
|
+
let loaded;
|
|
106
|
+
try {
|
|
107
|
+
breaker.chargeOrTrip({ worktrees: 1 });
|
|
108
|
+
loaded = await loadScenario(opts.scenario);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
return tripFromError(breaker, err, logger, opts.scenario, runId, execute);
|
|
112
|
+
}
|
|
113
|
+
const guard = opts.guard ?? createToolGuard({ mode: 'enforce' });
|
|
114
|
+
const workspaceRoot = resolveOrCwd(opts.cwd);
|
|
115
|
+
const env = await resolveExecutionEnv({
|
|
116
|
+
backend,
|
|
117
|
+
guard,
|
|
118
|
+
workspaceRoot,
|
|
119
|
+
...(opts.seededCopyDir !== undefined ? { seededCopyDir: opts.seededCopyDir } : {}),
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
// ── 2. replay (query-only default — no mutate path fires) ─────────────────
|
|
123
|
+
const replayed = await replayScenario(loaded.scenario, opts.dispatch);
|
|
124
|
+
// ── 3. diff vs golden ─────────────────────────────────────────────────────
|
|
125
|
+
const diff = diffEnvelopes(loaded.scenario.ops, replayed, loaded.golden.envelopes);
|
|
126
|
+
if (diff.regressions.length === 0) {
|
|
127
|
+
logger.debug({ scenario: opts.scenario, runId }, 'self-improve run green — no regression');
|
|
128
|
+
return {
|
|
129
|
+
outcome: 'green',
|
|
130
|
+
scenario: opts.scenario,
|
|
131
|
+
runId,
|
|
132
|
+
executed: execute,
|
|
133
|
+
regressions: [],
|
|
134
|
+
questionHash: null,
|
|
135
|
+
draftPr: null,
|
|
136
|
+
breaker: breaker.state,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const questionHash = computeQuestionHash(diff);
|
|
140
|
+
// Pre-flight gate check — never act on a fix that would itself regress a gate.
|
|
141
|
+
if (opts.gateRedCheck !== undefined && (await opts.gateRedCheck())) {
|
|
142
|
+
breaker.trip('gateRed', 'cleo check arch --strict reported RED before persist/egress');
|
|
143
|
+
logger.warn({ scenario: opts.scenario, runId }, 'self-improve halted: architectural gate RED');
|
|
144
|
+
return halted(opts.scenario, diff.regressions, questionHash);
|
|
145
|
+
}
|
|
146
|
+
// ── default-OFF gate: no write / no PR without --execute ───────────────────
|
|
147
|
+
if (!execute) {
|
|
148
|
+
logger.info({ scenario: opts.scenario, runId, regressions: diff.regressions.length }, 'self-improve regression detected (DRY-RUN — no DHQ write, no PR; pass --execute to act)');
|
|
149
|
+
return {
|
|
150
|
+
outcome: 'regression-dry-run',
|
|
151
|
+
scenario: opts.scenario,
|
|
152
|
+
runId,
|
|
153
|
+
executed: false,
|
|
154
|
+
regressions: diff.regressions,
|
|
155
|
+
questionHash,
|
|
156
|
+
draftPr: null,
|
|
157
|
+
breaker: breaker.state,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
// ── 4. emit ONE leased DHQ (require-mode lease throw ⇒ breaker trip) ────────
|
|
161
|
+
try {
|
|
162
|
+
await adapter.upsertOpenDhq({
|
|
163
|
+
dhqId: `DHQ-${questionHash.slice(0, 8)}`,
|
|
164
|
+
scenario: opts.scenario,
|
|
165
|
+
questionHash,
|
|
166
|
+
title: `selfimprove regression in '${opts.scenario}' (${diff.regressions.length} path(s))`,
|
|
167
|
+
regressionJson: JSON.stringify(diff),
|
|
168
|
+
severity: null,
|
|
169
|
+
runId,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
return tripFromError(breaker, err, logger, opts.scenario, runId, execute, diff.regressions, questionHash);
|
|
174
|
+
}
|
|
175
|
+
// ── 5. open ONE DRAFT PR (counts against maxPrs=1) + record url back ────────
|
|
176
|
+
let draftPr = null;
|
|
177
|
+
try {
|
|
178
|
+
breaker.chargeOrTrip({ prs: 1 });
|
|
179
|
+
draftPr = await openDraftPr({
|
|
180
|
+
scenario: opts.scenario,
|
|
181
|
+
diffPath: `selfimprove-${opts.scenario}.patch`,
|
|
182
|
+
title: `fix(selfimprove): ${opts.scenario} regression`,
|
|
183
|
+
body: `Auto-detected regression in the \`${opts.scenario}\` dogfood scenario (run ${runId}).`,
|
|
184
|
+
execute,
|
|
185
|
+
...(opts.cwd !== undefined ? { cwd: opts.cwd } : {}),
|
|
186
|
+
});
|
|
187
|
+
if (draftPr.kind === 'ok') {
|
|
188
|
+
await adapter.recordPrUrl(questionHash, draftPr.prUrl);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
return tripFromError(breaker, err, logger, opts.scenario, runId, execute, diff.regressions, questionHash);
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
outcome: 'regression-acted',
|
|
196
|
+
scenario: opts.scenario,
|
|
197
|
+
runId,
|
|
198
|
+
executed: true,
|
|
199
|
+
regressions: diff.regressions,
|
|
200
|
+
questionHash,
|
|
201
|
+
draftPr,
|
|
202
|
+
breaker: breaker.state,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
await env.cleanup();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Trip the breaker from a thrown error, classifying the reason, and return a
|
|
211
|
+
* `halted` result. A {@link LeaseUnavailableError} maps to `leaseUnavailable`; a
|
|
212
|
+
* {@link "./budget.js".BudgetExceededError} (already self-trips) maps to
|
|
213
|
+
* `budgetOverrun`; everything else from a write path maps to `dbError`.
|
|
214
|
+
*/
|
|
215
|
+
function tripFromError(breaker, err, logger, scenario, runId, executed, regressions = [], questionHash = null) {
|
|
216
|
+
let reason = 'dbError';
|
|
217
|
+
if (err instanceof LeaseUnavailableError) {
|
|
218
|
+
reason = 'leaseUnavailable';
|
|
219
|
+
}
|
|
220
|
+
else if (err !== null &&
|
|
221
|
+
typeof err === 'object' &&
|
|
222
|
+
err.code === 'E_SELFIMPROVE_BUDGET_EXCEEDED') {
|
|
223
|
+
reason = 'budgetOverrun';
|
|
224
|
+
}
|
|
225
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
226
|
+
breaker.trip(reason, detail);
|
|
227
|
+
logger.warn({ scenario, runId, reason, detail }, 'self-improve circuit-breaker tripped');
|
|
228
|
+
return {
|
|
229
|
+
outcome: 'halted',
|
|
230
|
+
scenario,
|
|
231
|
+
runId,
|
|
232
|
+
executed,
|
|
233
|
+
regressions,
|
|
234
|
+
questionHash,
|
|
235
|
+
draftPr: null,
|
|
236
|
+
breaker: breaker.state,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
export { DEFAULT_BUDGET };
|
|
240
|
+
//# sourceMappingURL=run-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-loop.js","sourceRoot":"","sources":["../../src/selfimprove/run-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAGH,OAAO,EAA4B,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACnG,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAkB,MAAM,mBAAmB,CAAC;AACpE,OAAO,EACL,cAAc,EAGd,cAAc,EACd,aAAa,GAEd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAmB,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAsB,WAAW,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAkB,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAuB,cAAc,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAuB,YAAY,EAAE,MAAM,eAAe,CAAC;AAgFlE;;GAEG;AACH,IAAI,YAAgC,CAAC;AACrC,KAAK,UAAU,eAAe;IAC5B,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;QACn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