@senpi-ai/runtime 1.1.2 → 3.0.3
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 +10 -9
- package/dist/actions/action-runtime-module.d.ts.map +1 -1
- package/dist/actions/action-runtime-module.js +1 -1
- package/dist/actions/action-runtime-module.js.map +1 -1
- package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
- package/dist/actions/close-position/close-position.action.js +61 -14
- package/dist/actions/close-position/close-position.action.js.map +1 -1
- package/dist/actions/decision-engine.d.ts.map +1 -1
- package/dist/actions/decision-engine.js +3 -0
- package/dist/actions/decision-engine.js.map +1 -1
- package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
- package/dist/actions/open-position/open-position.action.js +161 -26
- package/dist/actions/open-position/open-position.action.js.map +1 -1
- package/dist/actions/position-tracker/position-tracker.action.d.ts +6 -0
- package/dist/actions/position-tracker/position-tracker.action.d.ts.map +1 -1
- package/dist/actions/position-tracker/position-tracker.action.js +48 -0
- package/dist/actions/position-tracker/position-tracker.action.js.map +1 -1
- package/dist/actions/tracking-helpers.d.ts +16 -1
- package/dist/actions/tracking-helpers.d.ts.map +1 -1
- package/dist/actions/tracking-helpers.js +55 -9
- package/dist/actions/tracking-helpers.js.map +1 -1
- package/dist/actions/types.d.ts +10 -2
- package/dist/actions/types.d.ts.map +1 -1
- package/dist/actions/types.js +8 -0
- package/dist/actions/types.js.map +1 -1
- package/dist/cli/guide-commands.d.ts.map +1 -1
- package/dist/cli/guide-commands.js +84 -82
- package/dist/cli/guide-commands.js.map +1 -1
- package/dist/cli/senpi-commands.d.ts.map +1 -1
- package/dist/cli/senpi-commands.js +16 -110
- package/dist/cli/senpi-commands.js.map +1 -1
- package/dist/constants/dsl/index.d.ts +2 -0
- package/dist/constants/dsl/index.d.ts.map +1 -1
- package/dist/constants/dsl/index.js +2 -0
- package/dist/constants/dsl/index.js.map +1 -1
- package/dist/dsl/config/parse-tiers.d.ts.map +1 -1
- package/dist/dsl/config/parse-tiers.js +6 -2
- package/dist/dsl/config/parse-tiers.js.map +1 -1
- package/dist/dsl/engine-client/config-mapping.d.ts +3 -1
- package/dist/dsl/engine-client/config-mapping.d.ts.map +1 -1
- package/dist/dsl/engine-client/config-mapping.js +3 -1
- package/dist/dsl/engine-client/config-mapping.js.map +1 -1
- package/dist/dsl/engine-client/event-mapping.d.ts +2 -0
- package/dist/dsl/engine-client/event-mapping.d.ts.map +1 -1
- package/dist/dsl/engine-client/event-mapping.js +3 -0
- package/dist/dsl/engine-client/event-mapping.js.map +1 -1
- package/dist/dsl/events/build-closed-event.d.ts.map +1 -1
- package/dist/dsl/events/build-closed-event.js +1 -0
- package/dist/dsl/events/build-closed-event.js.map +1 -1
- package/dist/dsl/events/guards.d.ts.map +1 -1
- package/dist/dsl/events/guards.js +10 -0
- package/dist/dsl/events/guards.js.map +1 -1
- package/dist/dsl/events/handlers.d.ts +18 -2
- package/dist/dsl/events/handlers.d.ts.map +1 -1
- package/dist/dsl/events/handlers.js +304 -208
- package/dist/dsl/events/handlers.js.map +1 -1
- package/dist/dsl/events/initial-state.d.ts.map +1 -1
- package/dist/dsl/events/initial-state.js +3 -1
- package/dist/dsl/events/initial-state.js.map +1 -1
- package/dist/dsl/monitor/create-monitor.d.ts +15 -0
- package/dist/dsl/monitor/create-monitor.d.ts.map +1 -1
- package/dist/dsl/monitor/create-monitor.js +76 -9
- package/dist/dsl/monitor/create-monitor.js.map +1 -1
- package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
- package/dist/dsl/monitor/process-one-position.js +268 -82
- package/dist/dsl/monitor/process-one-position.js.map +1 -1
- package/dist/dsl/plugin/index.d.ts +16 -1
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js +35 -4
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/dsl/plugin/options.d.ts +18 -0
- package/dist/dsl/plugin/options.d.ts.map +1 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +272 -32
- package/dist/index.js.map +1 -1
- package/dist/recording/emitter.d.ts +27 -0
- package/dist/recording/emitter.d.ts.map +1 -0
- package/dist/recording/emitter.js +2 -0
- package/dist/recording/emitter.js.map +1 -0
- package/dist/recording/identity.d.ts +34 -0
- package/dist/recording/identity.d.ts.map +1 -0
- package/dist/recording/identity.js +2 -0
- package/dist/recording/identity.js.map +1 -0
- package/dist/recording/index.d.ts +11 -0
- package/dist/recording/index.d.ts.map +1 -0
- package/dist/recording/index.js +2 -0
- package/dist/recording/index.js.map +1 -0
- package/dist/recording/noop-emitter.d.ts +23 -0
- package/dist/recording/noop-emitter.d.ts.map +1 -0
- package/dist/recording/noop-emitter.js +22 -0
- package/dist/recording/noop-emitter.js.map +1 -0
- package/dist/recording/otel/attributes.d.ts +35 -0
- package/dist/recording/otel/attributes.d.ts.map +1 -0
- package/dist/recording/otel/attributes.js +131 -0
- package/dist/recording/otel/attributes.js.map +1 -0
- package/dist/recording/otel/constants.d.ts +123 -0
- package/dist/recording/otel/constants.d.ts.map +1 -0
- package/dist/recording/otel/constants.js +172 -0
- package/dist/recording/otel/constants.js.map +1 -0
- package/dist/recording/otel/ids.d.ts +25 -0
- package/dist/recording/otel/ids.d.ts.map +1 -0
- package/dist/recording/otel/ids.js +37 -0
- package/dist/recording/otel/ids.js.map +1 -0
- package/dist/recording/otel/index.d.ts +13 -0
- package/dist/recording/otel/index.d.ts.map +1 -0
- package/dist/recording/otel/index.js +9 -0
- package/dist/recording/otel/index.js.map +1 -0
- package/dist/recording/otel/mappers.d.ts +100 -0
- package/dist/recording/otel/mappers.d.ts.map +1 -0
- package/dist/recording/otel/mappers.js +683 -0
- package/dist/recording/otel/mappers.js.map +1 -0
- package/dist/recording/otel/otel-emitter.d.ts +43 -0
- package/dist/recording/otel/otel-emitter.d.ts.map +1 -0
- package/dist/recording/otel/otel-emitter.js +99 -0
- package/dist/recording/otel/otel-emitter.js.map +1 -0
- package/dist/recording/otel/redaction.d.ts +47 -0
- package/dist/recording/otel/redaction.d.ts.map +1 -0
- package/dist/recording/otel/redaction.js +88 -0
- package/dist/recording/otel/redaction.js.map +1 -0
- package/dist/recording/records.d.ts +565 -0
- package/dist/recording/records.d.ts.map +1 -0
- package/dist/recording/records.js +14 -0
- package/dist/recording/records.js.map +1 -0
- package/dist/recording/transport/batcher.d.ts +59 -0
- package/dist/recording/transport/batcher.d.ts.map +1 -0
- package/dist/recording/transport/batcher.js +234 -0
- package/dist/recording/transport/batcher.js.map +1 -0
- package/dist/recording/transport/client.d.ts +41 -0
- package/dist/recording/transport/client.d.ts.map +1 -0
- package/dist/recording/transport/client.js +69 -0
- package/dist/recording/transport/client.js.map +1 -0
- package/dist/recording/transport/config.d.ts +53 -0
- package/dist/recording/transport/config.d.ts.map +1 -0
- package/dist/recording/transport/config.js +41 -0
- package/dist/recording/transport/config.js.map +1 -0
- package/dist/recording/transport/index.d.ts +16 -0
- package/dist/recording/transport/index.d.ts.map +1 -0
- package/dist/recording/transport/index.js +12 -0
- package/dist/recording/transport/index.js.map +1 -0
- package/dist/recording/transport/rows.d.ts +88 -0
- package/dist/recording/transport/rows.d.ts.map +1 -0
- package/dist/recording/transport/rows.js +15 -0
- package/dist/recording/transport/rows.js.map +1 -0
- package/dist/recording/wiring/emitter-factory.d.ts +39 -0
- package/dist/recording/wiring/emitter-factory.d.ts.map +1 -0
- package/dist/recording/wiring/emitter-factory.js +62 -0
- package/dist/recording/wiring/emitter-factory.js.map +1 -0
- package/dist/recording/wiring/identity.d.ts +27 -0
- package/dist/recording/wiring/identity.d.ts.map +1 -0
- package/dist/recording/wiring/identity.js +51 -0
- package/dist/recording/wiring/identity.js.map +1 -0
- package/dist/recording/wiring/index.d.ts +12 -0
- package/dist/recording/wiring/index.d.ts.map +1 -0
- package/dist/recording/wiring/index.js +9 -0
- package/dist/recording/wiring/index.js.map +1 -0
- package/dist/recording/wiring/record-builders.d.ts +107 -0
- package/dist/recording/wiring/record-builders.d.ts.map +1 -0
- package/dist/recording/wiring/record-builders.js +706 -0
- package/dist/recording/wiring/record-builders.js.map +1 -0
- package/dist/recording/wiring/subscriber.d.ts +28 -0
- package/dist/recording/wiring/subscriber.d.ts.map +1 -0
- package/dist/recording/wiring/subscriber.js +173 -0
- package/dist/recording/wiring/subscriber.js.map +1 -0
- package/dist/recording/wiring/values.d.ts +19 -0
- package/dist/recording/wiring/values.d.ts.map +1 -0
- package/dist/recording/wiring/values.js +49 -0
- package/dist/recording/wiring/values.js.map +1 -0
- package/dist/runtime/auto-update/command-runner.d.ts.map +1 -1
- package/dist/runtime/auto-update/command-runner.js +5 -1
- package/dist/runtime/auto-update/command-runner.js.map +1 -1
- package/dist/runtime/auto-update/resolve-package-name.d.ts +10 -0
- package/dist/runtime/auto-update/resolve-package-name.d.ts.map +1 -0
- package/dist/runtime/auto-update/resolve-package-name.js +35 -0
- package/dist/runtime/auto-update/resolve-package-name.js.map +1 -0
- package/dist/runtime/auto-update/run-update-command.d.ts +2 -0
- package/dist/runtime/auto-update/run-update-command.d.ts.map +1 -0
- package/dist/runtime/auto-update/run-update-command.js +37 -0
- package/dist/runtime/auto-update/run-update-command.js.map +1 -0
- package/dist/runtime/create-runtime-context.d.ts +2 -0
- package/dist/runtime/create-runtime-context.d.ts.map +1 -1
- package/dist/runtime/create-runtime-context.js +1 -0
- package/dist/runtime/create-runtime-context.js.map +1 -1
- package/dist/runtime/create-scanner-module.d.ts +4 -3
- package/dist/runtime/create-scanner-module.d.ts.map +1 -1
- package/dist/runtime/create-scanner-module.js +14 -5
- package/dist/runtime/create-scanner-module.js.map +1 -1
- package/dist/runtime/create-scanner-providers-for-run.d.ts.map +1 -1
- package/dist/runtime/create-scanner-providers-for-run.js +12 -1
- package/dist/runtime/create-scanner-providers-for-run.js.map +1 -1
- package/dist/runtime/load-runtime-config.d.ts +9 -0
- package/dist/runtime/load-runtime-config.d.ts.map +1 -1
- package/dist/runtime/load-runtime-config.js +41 -8
- package/dist/runtime/load-runtime-config.js.map +1 -1
- package/dist/runtime/map-strategies-registration.js +7 -8
- package/dist/runtime/map-strategies-registration.js.map +1 -1
- package/dist/runtime/map-strategies.d.ts.map +1 -1
- package/dist/runtime/map-strategies.js +12 -3
- package/dist/runtime/map-strategies.js.map +1 -1
- package/dist/runtime/recipe-version.d.ts +1 -1
- package/dist/runtime/recipe-version.d.ts.map +1 -1
- package/dist/runtime/recipe-version.js +1 -1
- package/dist/runtime/recipe-version.js.map +1 -1
- package/dist/runtime/reconcile-decide.d.ts +73 -0
- package/dist/runtime/reconcile-decide.d.ts.map +1 -0
- package/dist/runtime/reconcile-decide.js +186 -0
- package/dist/runtime/reconcile-decide.js.map +1 -0
- package/dist/runtime/reconcile-run.d.ts +62 -0
- package/dist/runtime/reconcile-run.d.ts.map +1 -0
- package/dist/runtime/reconcile-run.js +173 -0
- package/dist/runtime/reconcile-run.js.map +1 -0
- package/dist/runtime/reconcile-state.d.ts +44 -0
- package/dist/runtime/reconcile-state.d.ts.map +1 -1
- package/dist/runtime/reconcile-state.js +80 -44
- package/dist/runtime/reconcile-state.js.map +1 -1
- package/dist/runtime/risk-guard.d.ts +10 -0
- package/dist/runtime/risk-guard.d.ts.map +1 -1
- package/dist/runtime/risk-guard.js +23 -24
- package/dist/runtime/risk-guard.js.map +1 -1
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +3 -2
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/runtime-schema.d.ts +4056 -793
- package/dist/runtime/runtime-schema.d.ts.map +1 -1
- package/dist/runtime/runtime-schema.js +183 -46
- package/dist/runtime/runtime-schema.js.map +1 -1
- package/dist/runtime/runtime-version.d.ts +3 -6
- package/dist/runtime/runtime-version.d.ts.map +1 -1
- package/dist/runtime/runtime-version.js +3 -6
- package/dist/runtime/runtime-version.js.map +1 -1
- package/dist/runtime/runtime.d.ts +47 -0
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +517 -134
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/scanner-registry.d.ts +1 -1
- package/dist/runtime/scanner-registry.d.ts.map +1 -1
- package/dist/runtime/scanner-registry.js +3 -12
- package/dist/runtime/scanner-registry.js.map +1 -1
- package/dist/runtime/strategy-lifecycle.d.ts +45 -0
- package/dist/runtime/strategy-lifecycle.d.ts.map +1 -0
- package/dist/runtime/strategy-lifecycle.js +117 -0
- package/dist/runtime/strategy-lifecycle.js.map +1 -0
- package/dist/runtime/strategy-registry.d.ts +6 -0
- package/dist/runtime/strategy-registry.d.ts.map +1 -1
- package/dist/runtime/strategy-registry.js +1 -0
- package/dist/runtime/strategy-registry.js.map +1 -1
- package/dist/runtime/supervisor/long-running-supervisor.d.ts +222 -0
- package/dist/runtime/supervisor/long-running-supervisor.d.ts.map +1 -0
- package/dist/runtime/supervisor/long-running-supervisor.js +625 -0
- package/dist/runtime/supervisor/long-running-supervisor.js.map +1 -0
- package/dist/runtime/supervisor/orphan-sweep.d.ts +36 -0
- package/dist/runtime/supervisor/orphan-sweep.d.ts.map +1 -0
- package/dist/runtime/supervisor/orphan-sweep.js +255 -0
- package/dist/runtime/supervisor/orphan-sweep.js.map +1 -0
- package/dist/runtime/supervisor/supervisor-utils.d.ts +37 -0
- package/dist/runtime/supervisor/supervisor-utils.d.ts.map +1 -0
- package/dist/runtime/supervisor/supervisor-utils.js +175 -0
- package/dist/runtime/supervisor/supervisor-utils.js.map +1 -0
- package/dist/runtime-api/handlers/ingest-signals.d.ts +3 -3
- package/dist/runtime-api/handlers/ingest-signals.js +3 -3
- package/dist/runtime-api/intake/acceptance-record.d.ts +103 -0
- package/dist/runtime-api/intake/acceptance-record.d.ts.map +1 -0
- package/dist/runtime-api/intake/acceptance-record.js +192 -0
- package/dist/runtime-api/intake/acceptance-record.js.map +1 -0
- package/dist/runtime-api/intake/intake-context.d.ts +31 -0
- package/dist/runtime-api/intake/intake-context.d.ts.map +1 -0
- package/dist/runtime-api/intake/intake-context.js +21 -0
- package/dist/runtime-api/intake/intake-context.js.map +1 -0
- package/dist/runtime-api/intake/intake-mount.d.ts +118 -0
- package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -0
- package/dist/runtime-api/intake/intake-mount.js +193 -0
- package/dist/runtime-api/intake/intake-mount.js.map +1 -0
- package/dist/runtime-api/intake/liveness-store.d.ts +32 -0
- package/dist/runtime-api/intake/liveness-store.d.ts.map +1 -0
- package/dist/runtime-api/intake/liveness-store.js +31 -0
- package/dist/runtime-api/intake/liveness-store.js.map +1 -0
- package/dist/runtime-api/intake/process-error-post.d.ts +15 -0
- package/dist/runtime-api/intake/process-error-post.d.ts.map +1 -0
- package/dist/runtime-api/intake/process-error-post.js +19 -0
- package/dist/runtime-api/intake/process-error-post.js.map +1 -0
- package/dist/runtime-api/intake/process-signal-post.d.ts +73 -0
- package/dist/runtime-api/intake/process-signal-post.d.ts.map +1 -0
- package/dist/runtime-api/intake/process-signal-post.js +188 -0
- package/dist/runtime-api/intake/process-signal-post.js.map +1 -0
- package/dist/runtime-api/intake/scanner-launcher.d.ts +133 -0
- package/dist/runtime-api/intake/scanner-launcher.d.ts.map +1 -0
- package/dist/runtime-api/intake/scanner-launcher.js +204 -0
- package/dist/runtime-api/intake/scanner-launcher.js.map +1 -0
- package/dist/runtime-api/intake/scanner-registry.d.ts +36 -0
- package/dist/runtime-api/intake/scanner-registry.d.ts.map +1 -0
- package/dist/runtime-api/intake/scanner-registry.js +29 -0
- package/dist/runtime-api/intake/scanner-registry.js.map +1 -0
- package/dist/runtime-api/intake/types.d.ts +61 -0
- package/dist/runtime-api/intake/types.d.ts.map +1 -0
- package/dist/runtime-api/intake/types.js +8 -0
- package/dist/runtime-api/intake/types.js.map +1 -0
- package/dist/runtime-api/routes/signals.d.ts +20 -40
- package/dist/runtime-api/routes/signals.d.ts.map +1 -1
- package/dist/runtime-api/routes/signals.js +119 -75
- package/dist/runtime-api/routes/signals.js.map +1 -1
- package/dist/runtime-api/routes/signals.schema.d.ts +24 -86
- package/dist/runtime-api/routes/signals.schema.d.ts.map +1 -1
- package/dist/runtime-api/routes/signals.schema.js +35 -50
- package/dist/runtime-api/routes/signals.schema.js.map +1 -1
- package/dist/runtime-api/server.d.ts +15 -6
- package/dist/runtime-api/server.d.ts.map +1 -1
- package/dist/runtime-api/server.js +12 -12
- package/dist/runtime-api/server.js.map +1 -1
- package/dist/scanners/events.d.ts +6 -0
- package/dist/scanners/events.d.ts.map +1 -1
- package/dist/scanners/events.js.map +1 -1
- package/dist/scanners/external/scaffold/__init__.py +16 -0
- package/dist/scanners/external/scaffold/__main__.py +155 -0
- package/dist/scanners/external/scaffold/ctx.py +78 -0
- package/dist/scanners/external/scaffold/delivery.py +263 -0
- package/dist/scanners/external/scaffold/entrypoint_loader.py +151 -0
- package/dist/scanners/external/scaffold/http_post.py +70 -0
- package/dist/scanners/external/scaffold/journal.py +247 -0
- package/dist/scanners/external/scaffold/loop_primitives.py +65 -0
- package/dist/scanners/external/scaffold/requirements.txt +11 -0
- package/dist/scanners/external/scaffold/scaffold.py +361 -0
- package/dist/scanners/external/scaffold/scaffold_state.py +114 -0
- package/dist/scanners/external/scaffold/senpi_mcp.py +250 -0
- package/dist/scanners/external/scaffold/signal_envelope.py +220 -0
- package/dist/scanners/external/scaffold/state_manager.py +175 -0
- package/dist/scanners/external-scanner-receiver.d.ts +17 -1
- package/dist/scanners/external-scanner-receiver.d.ts.map +1 -1
- package/dist/scanners/external-scanner-receiver.js +16 -3
- package/dist/scanners/external-scanner-receiver.js.map +1 -1
- package/dist/scanners/implementations/external-scanner.d.ts.map +1 -1
- package/dist/scanners/implementations/external-scanner.js +7 -1
- package/dist/scanners/implementations/external-scanner.js.map +1 -1
- package/dist/scanners/implementations/momentum.d.ts.map +1 -1
- package/dist/scanners/implementations/momentum.js +16 -0
- package/dist/scanners/implementations/momentum.js.map +1 -1
- package/dist/scanners/runtime-module.d.ts.map +1 -1
- package/dist/scanners/runtime-module.js +9 -1
- package/dist/scanners/runtime-module.js.map +1 -1
- package/dist/scripts/run-dsl-standalone-live.d.ts +1 -1
- package/dist/scripts/run-dsl-standalone-live.js +5 -3
- package/dist/scripts/run-dsl-standalone-live.js.map +1 -1
- package/dist/senpi/client.d.ts +56 -4
- package/dist/senpi/client.d.ts.map +1 -1
- package/dist/senpi/client.js +123 -24
- package/dist/senpi/client.js.map +1 -1
- package/dist/senpi/index.d.ts +2 -1
- package/dist/senpi/index.d.ts.map +1 -1
- package/dist/senpi/index.js +1 -1
- package/dist/senpi/index.js.map +1 -1
- package/dist/senpi/types.d.ts +1 -2
- package/dist/senpi/types.d.ts.map +1 -1
- package/dist/state/state-manager.d.ts +17 -0
- package/dist/state/state-manager.d.ts.map +1 -1
- package/dist/state/state-manager.js +55 -4
- package/dist/state/state-manager.js.map +1 -1
- package/dist/strategy/strategy-state.d.ts +9 -1
- package/dist/strategy/strategy-state.d.ts.map +1 -1
- package/dist/strategy/strategy-state.js +62 -9
- package/dist/strategy/strategy-state.js.map +1 -1
- package/dist/tracking/build-rehydrate-items.d.ts +15 -0
- package/dist/tracking/build-rehydrate-items.d.ts.map +1 -0
- package/dist/tracking/build-rehydrate-items.js +19 -0
- package/dist/tracking/build-rehydrate-items.js.map +1 -0
- package/dist/tracking/constants.d.ts.map +1 -1
- package/dist/tracking/constants.js +2 -0
- package/dist/tracking/constants.js.map +1 -1
- package/dist/tracking/index.d.ts +3 -0
- package/dist/tracking/index.d.ts.map +1 -1
- package/dist/tracking/index.js +2 -0
- package/dist/tracking/index.js.map +1 -1
- package/dist/tracking/position-id-registry.d.ts +69 -0
- package/dist/tracking/position-id-registry.d.ts.map +1 -0
- package/dist/tracking/position-id-registry.js +139 -0
- package/dist/tracking/position-id-registry.js.map +1 -0
- package/dist/tracking/spans/fan-out-span-transport.d.ts +22 -0
- package/dist/tracking/spans/fan-out-span-transport.d.ts.map +1 -0
- package/dist/tracking/spans/fan-out-span-transport.js +49 -0
- package/dist/tracking/spans/fan-out-span-transport.js.map +1 -0
- package/dist/tracking/spans/otel/fit-row-budget.d.ts +22 -0
- package/dist/tracking/spans/otel/fit-row-budget.d.ts.map +1 -0
- package/dist/tracking/spans/otel/fit-row-budget.js +91 -0
- package/dist/tracking/spans/otel/fit-row-budget.js.map +1 -0
- package/dist/tracking/spans/otel/map-span-to-trace-row.d.ts +16 -0
- package/dist/tracking/spans/otel/map-span-to-trace-row.d.ts.map +1 -0
- package/dist/tracking/spans/otel/map-span-to-trace-row.js +227 -0
- package/dist/tracking/spans/otel/map-span-to-trace-row.js.map +1 -0
- package/dist/tracking/spans/otel/recording-span-transport.d.ts +43 -0
- package/dist/tracking/spans/otel/recording-span-transport.d.ts.map +1 -0
- package/dist/tracking/spans/otel/recording-span-transport.js +67 -0
- package/dist/tracking/spans/otel/recording-span-transport.js.map +1 -0
- package/dist/tracking/spans/otel/span-ids.d.ts +22 -0
- package/dist/tracking/spans/otel/span-ids.d.ts.map +1 -0
- package/dist/tracking/spans/otel/span-ids.js +32 -0
- package/dist/tracking/spans/otel/span-ids.js.map +1 -0
- package/dist/tracking/spans/plugin-span-tracker.d.ts +6 -0
- package/dist/tracking/spans/plugin-span-tracker.d.ts.map +1 -1
- package/dist/tracking/spans/plugin-span-tracker.js +82 -9
- package/dist/tracking/spans/plugin-span-tracker.js.map +1 -1
- package/dist/tracking/spans/redact-pii.d.ts +3 -1
- package/dist/tracking/spans/redact-pii.d.ts.map +1 -1
- package/dist/tracking/spans/redact-pii.js +5 -1
- package/dist/tracking/spans/redact-pii.js.map +1 -1
- package/dist/tracking/spans/span-transport.d.ts +6 -0
- package/dist/tracking/spans/span-transport.d.ts.map +1 -1
- package/dist/tracking/spans/span-transport.js +1 -1
- package/dist/tracking/spans/span-transport.js.map +1 -1
- package/dist/types/dsl/index.d.ts +24 -1
- package/dist/types/dsl/index.d.ts.map +1 -1
- package/dist/types/hooks.d.ts +1 -0
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/hooks.js +1 -0
- package/dist/types/hooks.js.map +1 -1
- package/dist/types/runtime.d.ts +6 -0
- package/dist/types/runtime.d.ts.map +1 -1
- package/dist/types/scanner.d.ts +7 -0
- package/dist/types/scanner.d.ts.map +1 -1
- package/dist/types/strategy.d.ts +3 -1
- package/dist/types/strategy.d.ts.map +1 -1
- package/dist/utils/keyed-mutex.d.ts +37 -0
- package/dist/utils/keyed-mutex.d.ts.map +1 -0
- package/dist/utils/keyed-mutex.js +77 -0
- package/dist/utils/keyed-mutex.js.map +1 -0
- package/dist/utils/safe-spawn.d.ts +6 -0
- package/dist/utils/safe-spawn.d.ts.map +1 -0
- package/dist/utils/safe-spawn.js +62 -0
- package/dist/utils/safe-spawn.js.map +1 -0
- package/examples/strategies/README.md +17 -12
- package/examples/strategies/iguana/README.md +135 -0
- package/examples/strategies/iguana/recipe.yaml +137 -0
- package/examples/strategies/iguana/scanners/scan.py +243 -0
- package/examples/strategies/iguana/scanners/scoring.py +152 -0
- package/examples/strategies/raptor/README.md +156 -0
- package/examples/strategies/raptor/recipe.yaml +154 -0
- package/examples/strategies/raptor/scanners/scan.py +349 -0
- package/examples/strategies/raptor/scanners/scoring.py +452 -0
- package/examples/strategies/spider/README.md +89 -0
- package/examples/strategies/spider/scalp/recipe.yaml +129 -0
- package/examples/strategies/spider/scalp/scanners/scan.py +219 -0
- package/examples/strategies/spider/scalp/scanners/scoring.py +179 -0
- package/examples/strategies/spider/swing/recipe.yaml +137 -0
- package/examples/strategies/spider/swing/scanners/scan.py +334 -0
- package/examples/strategies/spider/swing/scanners/scoring.py +184 -0
- package/examples/strategies/turbine/README.md +166 -0
- package/examples/strategies/turbine/recipe-runners.yaml +123 -0
- package/examples/strategies/turbine/recipe-volume.yaml +129 -0
- package/examples/strategies/turbine/scanners/scan.py +283 -0
- package/examples/strategies/turbine/scanners/scoring.py +190 -0
- package/openclaw.plugin.json +12 -1
- package/package.json +3 -3
- package/dist/runtime-api/handlers/group-by-scanner.d.ts +0 -43
- package/dist/runtime-api/handlers/group-by-scanner.d.ts.map +0 -1
- package/dist/runtime-api/handlers/group-by-scanner.js +0 -43
- package/dist/runtime-api/handlers/group-by-scanner.js.map +0 -1
- package/dist/scanners/external/liquidation-watchdog/README.md +0 -107
- package/dist/scanners/external/liquidation-watchdog/liquidation-watchdog.yaml +0 -48
- package/dist/scanners/external/liquidation-watchdog/producer.mjs +0 -336
- package/dist/scanners/external/momentum/README.md +0 -148
- package/dist/scanners/external/momentum/momentum.yaml +0 -116
- package/dist/scanners/external/momentum/producer.mjs +0 -251
- package/dist/scanners/external/shared/ingest.mjs +0 -112
- package/examples/README.md +0 -89
- package/examples/scanners-consumer-quickstart.mjs +0 -134
- package/examples/scanners-emerging-movers-v4.mjs +0 -287
- package/examples/scanners-liquidation-watchdog.mjs +0 -341
- package/examples/scanners-live-mcp.mjs +0 -208
- package/examples/scanners-multi-strategy.mjs +0 -165
- package/examples/scanners-position-tracker-e2e.mjs +0 -225
- package/examples/scanners-scheduled-events.mjs +0 -96
- package/examples/scanners-senpi-provider-client.mjs +0 -182
- package/examples/scanners-single-strategy.mjs +0 -198
- package/examples/strategies/dsl-showcase.yaml +0 -68
- package/examples/strategies/dsl.yaml +0 -51
- package/examples/strategies/fox-minimal-loosened.yaml +0 -240
- package/examples/strategies/fox-minimal.yaml +0 -242
- package/examples/strategies/minimal.yaml +0 -46
- package/examples/strategies/momentum/how-it-works.md +0 -48
- package/examples/strategies/momentum/momentum-guarded.yaml +0 -161
- package/examples/strategies/risk-showcase.yaml +0 -93
- package/examples/strategies/viper.yaml +0 -67
- package/examples/strategies/wolf.yaml +0 -72
- package/examples/yamls/sample-with-dsl-and-emerging-movers.yaml +0 -123
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Minimal stdlib HTTP POST helper.
|
|
2
|
+
|
|
3
|
+
post_json(url, body, timeout) -> (status_code, parsed_or_None)
|
|
4
|
+
|
|
5
|
+
POSTs `body` (a dict) as JSON to `url`. Fresh connection per call (no pooling).
|
|
6
|
+
Returns (status_code, parsed_json) on a parseable response.
|
|
7
|
+
Returns (status_code, None) when the response body is not valid JSON.
|
|
8
|
+
Raises TransportError on connection failure, timeout, or transport-level error.
|
|
9
|
+
|
|
10
|
+
Constants:
|
|
11
|
+
SIGNALS_PATH = "/signals"
|
|
12
|
+
ERRORS_PATH = "/errors"
|
|
13
|
+
|
|
14
|
+
No third-party dependencies.
|
|
15
|
+
|
|
16
|
+
Note: the intake route is mounted at /signals. SIGNALS_PATH is already correct.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import json
|
|
22
|
+
import urllib.error
|
|
23
|
+
import urllib.request
|
|
24
|
+
from typing import Any
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
SIGNALS_PATH = "/signals"
|
|
28
|
+
ERRORS_PATH = "/errors"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class TransportError(Exception):
|
|
32
|
+
"""Raised on connection failure, timeout, or non-JSON transport body."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def post_json(url: str, body: dict, timeout: float) -> tuple[int, Any]:
|
|
36
|
+
"""POST body as JSON to url.
|
|
37
|
+
|
|
38
|
+
Returns (status_code, parsed_json_or_None).
|
|
39
|
+
Raises TransportError on connection/timeout failures.
|
|
40
|
+
"""
|
|
41
|
+
data = json.dumps(body).encode("utf-8")
|
|
42
|
+
req = urllib.request.Request(
|
|
43
|
+
url,
|
|
44
|
+
data=data,
|
|
45
|
+
headers={
|
|
46
|
+
"Content-Type": "application/json",
|
|
47
|
+
"Content-Length": str(len(data)),
|
|
48
|
+
},
|
|
49
|
+
method="POST",
|
|
50
|
+
)
|
|
51
|
+
try:
|
|
52
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
53
|
+
status = resp.status
|
|
54
|
+
raw = resp.read()
|
|
55
|
+
except urllib.error.HTTPError as exc:
|
|
56
|
+
# HTTPError has a status and a response body
|
|
57
|
+
status = exc.code
|
|
58
|
+
try:
|
|
59
|
+
raw = exc.read()
|
|
60
|
+
except Exception:
|
|
61
|
+
raw = b""
|
|
62
|
+
except (urllib.error.URLError, OSError, TimeoutError) as exc:
|
|
63
|
+
raise TransportError(str(exc)) from exc
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
parsed = json.loads(raw.decode("utf-8")) if raw else None
|
|
67
|
+
except (json.JSONDecodeError, UnicodeDecodeError):
|
|
68
|
+
parsed = None
|
|
69
|
+
|
|
70
|
+
return (status, parsed)
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"""On-disk delivery journal: append-only JSON-lines.
|
|
2
|
+
|
|
3
|
+
Journal(path: str | None)
|
|
4
|
+
path=None -> in-memory only; no file written. Never raises on corrupt file.
|
|
5
|
+
|
|
6
|
+
journal.record_produced(signal, *, now_ms) -> str
|
|
7
|
+
Appends a 'produced' line BEFORE the POST. Returns entry id (uuid4 hex).
|
|
8
|
+
If the asset already has a pending (undelivered) entry, drops the older
|
|
9
|
+
one with a 'dropped_superseded' outcome line and replaces it.
|
|
10
|
+
|
|
11
|
+
journal.record_outcome(entry_id, outcome, **fields) -> None
|
|
12
|
+
Appends a terminal 'outcome' line. Marks the id settled.
|
|
13
|
+
|
|
14
|
+
journal.pending() -> list
|
|
15
|
+
In-memory queue: newest undelivered per asset. Each entry exposes
|
|
16
|
+
.id, .asset, .signal, .valid_until (attribute access).
|
|
17
|
+
|
|
18
|
+
journal.replay(now_ms) -> None
|
|
19
|
+
Re-read the file, rebuild the settled set, re-queue valid+unsettled+newest
|
|
20
|
+
per-asset entries. Writes drop lines for stale/superseded. Skips corrupt
|
|
21
|
+
lines (logs journal_corrupt_line). Never raises.
|
|
22
|
+
|
|
23
|
+
journal.is_settled(entry_id) -> bool
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from __future__ import annotations
|
|
27
|
+
|
|
28
|
+
import json
|
|
29
|
+
import os
|
|
30
|
+
import sys
|
|
31
|
+
import uuid
|
|
32
|
+
from dataclasses import dataclass
|
|
33
|
+
from typing import Any
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _log(event: str, **fields: Any) -> None:
|
|
37
|
+
import time
|
|
38
|
+
record = {"event": event, "ts": time.time(), **fields}
|
|
39
|
+
print(f"[scaffold] {json.dumps(record)}", file=sys.stderr, flush=True)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass
|
|
43
|
+
class _Entry:
|
|
44
|
+
id: str
|
|
45
|
+
asset: str
|
|
46
|
+
signal: dict
|
|
47
|
+
valid_until: int
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class Journal:
|
|
51
|
+
"""Append-only JSONL delivery journal, in-memory or on-disk."""
|
|
52
|
+
|
|
53
|
+
def __init__(self, path: str | None) -> None:
|
|
54
|
+
self._path = path
|
|
55
|
+
self._settled: set[str] = set()
|
|
56
|
+
# asset -> _Entry (newest undelivered per asset)
|
|
57
|
+
self._queue: dict[str, _Entry] = {}
|
|
58
|
+
|
|
59
|
+
# ------------------------------------------------------------------
|
|
60
|
+
# Write helpers
|
|
61
|
+
# ------------------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
def _append(self, record: dict) -> None:
|
|
64
|
+
if self._path is None:
|
|
65
|
+
return
|
|
66
|
+
line = json.dumps(record) + "\n"
|
|
67
|
+
try:
|
|
68
|
+
with open(self._path, "a", encoding="utf-8") as fh:
|
|
69
|
+
fh.write(line)
|
|
70
|
+
except OSError as exc:
|
|
71
|
+
# Append failed (disk full, read-only fs, permissions, I/O error).
|
|
72
|
+
# We do NOT let this tear down the delivery sink: the safe direction
|
|
73
|
+
# is a dropped/lost signal (fail toward NOT trading), not a crash of
|
|
74
|
+
# the sink that would take down delivery for every other candidate.
|
|
75
|
+
# Log explicitly so the at-risk candidate is observable.
|
|
76
|
+
# TODO(observability): journal_append_failed must be captured by the
|
|
77
|
+
# observability stack and alerted on — a persistent append failure
|
|
78
|
+
# means signals are being silently dropped on this scanner.
|
|
79
|
+
_log(
|
|
80
|
+
"journal_append_failed",
|
|
81
|
+
path=self._path,
|
|
82
|
+
error=str(exc),
|
|
83
|
+
kind=record.get("kind"),
|
|
84
|
+
entry_id=record.get("id"),
|
|
85
|
+
asset=record.get("asset"),
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
# ------------------------------------------------------------------
|
|
89
|
+
# Public API
|
|
90
|
+
# ------------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
def record_produced(self, signal: dict, *, now_ms: int) -> str:
|
|
93
|
+
"""Write a 'produced' line and enqueue the signal. Returns entry id.
|
|
94
|
+
|
|
95
|
+
The entry id IS the wire `signal_id`: the journal stamps `signal_id` onto
|
|
96
|
+
the persisted/queued signal so the POSTed signal carries the dedup key, and
|
|
97
|
+
a replay re-uses the SAME id (no fresh id minted on restart). If the signal
|
|
98
|
+
already carries a `signal_id` (the delivery sink threaded the eid in via the
|
|
99
|
+
envelope), that id is re-used as the entry id; otherwise one is minted.
|
|
100
|
+
"""
|
|
101
|
+
existing = signal.get("signal_id")
|
|
102
|
+
entry_id = existing if isinstance(existing, str) and existing else uuid.uuid4().hex
|
|
103
|
+
# Stamp the id onto the wire signal so the persisted produced line and the
|
|
104
|
+
# POSTed body both carry signal_id == entry id.
|
|
105
|
+
signal["signal_id"] = entry_id
|
|
106
|
+
asset = signal.get("asset", "")
|
|
107
|
+
valid_until = signal.get("valid_until", 0)
|
|
108
|
+
|
|
109
|
+
# If there's already a pending entry for this asset, drop the old one.
|
|
110
|
+
if asset in self._queue:
|
|
111
|
+
old = self._queue[asset]
|
|
112
|
+
self._append({
|
|
113
|
+
"kind": "outcome",
|
|
114
|
+
"id": old.id,
|
|
115
|
+
"outcome": "dropped_superseded",
|
|
116
|
+
})
|
|
117
|
+
self._settled.add(old.id)
|
|
118
|
+
|
|
119
|
+
record = {
|
|
120
|
+
"kind": "produced",
|
|
121
|
+
"id": entry_id,
|
|
122
|
+
"asset": asset,
|
|
123
|
+
"produced_at": signal.get("produced_at", now_ms),
|
|
124
|
+
"valid_until": valid_until,
|
|
125
|
+
"signal": signal,
|
|
126
|
+
}
|
|
127
|
+
self._append(record)
|
|
128
|
+
|
|
129
|
+
entry = _Entry(id=entry_id, asset=asset, signal=signal, valid_until=valid_until)
|
|
130
|
+
self._queue[asset] = entry
|
|
131
|
+
return entry_id
|
|
132
|
+
|
|
133
|
+
def record_outcome(self, entry_id: str, outcome: str, **fields) -> None:
|
|
134
|
+
"""Write a terminal outcome line and mark the id settled."""
|
|
135
|
+
record = {"kind": "outcome", "id": entry_id, "outcome": outcome, **fields}
|
|
136
|
+
self._append(record)
|
|
137
|
+
self._settled.add(entry_id)
|
|
138
|
+
# Remove from in-memory queue
|
|
139
|
+
to_remove = [a for a, e in self._queue.items() if e.id == entry_id]
|
|
140
|
+
for a in to_remove:
|
|
141
|
+
del self._queue[a]
|
|
142
|
+
|
|
143
|
+
def pending(self) -> list:
|
|
144
|
+
"""Return list of pending _Entry objects (newest undelivered per asset)."""
|
|
145
|
+
return list(self._queue.values())
|
|
146
|
+
|
|
147
|
+
def is_settled(self, entry_id: str) -> bool:
|
|
148
|
+
return entry_id in self._settled
|
|
149
|
+
|
|
150
|
+
def replay(self, now_ms: int) -> None:
|
|
151
|
+
"""Re-read the journal file and rebuild the in-memory state.
|
|
152
|
+
|
|
153
|
+
Re-queues entries that are:
|
|
154
|
+
- not settled
|
|
155
|
+
- still valid (now_ms < valid_until; boundary == is expired)
|
|
156
|
+
- newest per asset (by produced_at)
|
|
157
|
+
|
|
158
|
+
Writes drop lines for stale/superseded unsettled entries.
|
|
159
|
+
Skips corrupt lines (logs journal_corrupt_line). Never raises.
|
|
160
|
+
"""
|
|
161
|
+
# Reset in-memory state before replay
|
|
162
|
+
self._settled = set()
|
|
163
|
+
self._queue = {}
|
|
164
|
+
|
|
165
|
+
if self._path is None or not os.path.exists(self._path):
|
|
166
|
+
return
|
|
167
|
+
|
|
168
|
+
produced: dict[str, dict] = {} # id -> produced record
|
|
169
|
+
settled: set[str] = set()
|
|
170
|
+
|
|
171
|
+
# --- Pass 1: parse all lines ---
|
|
172
|
+
try:
|
|
173
|
+
with open(self._path, "r", encoding="utf-8", errors="replace") as fh:
|
|
174
|
+
lines = fh.readlines()
|
|
175
|
+
except OSError:
|
|
176
|
+
return
|
|
177
|
+
|
|
178
|
+
for line in lines:
|
|
179
|
+
line = line.strip()
|
|
180
|
+
if not line:
|
|
181
|
+
continue
|
|
182
|
+
try:
|
|
183
|
+
obj = json.loads(line)
|
|
184
|
+
except (json.JSONDecodeError, ValueError, UnicodeDecodeError):
|
|
185
|
+
_log("journal_corrupt_line", path=self._path)
|
|
186
|
+
continue
|
|
187
|
+
|
|
188
|
+
if not isinstance(obj, dict):
|
|
189
|
+
_log("journal_corrupt_line", path=self._path)
|
|
190
|
+
continue
|
|
191
|
+
|
|
192
|
+
kind = obj.get("kind")
|
|
193
|
+
if kind == "produced":
|
|
194
|
+
eid = obj.get("id")
|
|
195
|
+
if eid:
|
|
196
|
+
produced[eid] = obj
|
|
197
|
+
elif kind == "outcome":
|
|
198
|
+
eid = obj.get("id")
|
|
199
|
+
if eid:
|
|
200
|
+
settled.add(eid)
|
|
201
|
+
|
|
202
|
+
self._settled = settled
|
|
203
|
+
|
|
204
|
+
# --- Pass 2: find newest per asset among unsettled produced ---
|
|
205
|
+
# unsettled produced: id -> record
|
|
206
|
+
unsettled = {eid: rec for eid, rec in produced.items() if eid not in settled}
|
|
207
|
+
|
|
208
|
+
# Build newest-per-asset map: asset -> (produced_at, id, record)
|
|
209
|
+
newest: dict[str, tuple] = {} # asset -> (produced_at, id, record)
|
|
210
|
+
for eid, rec in unsettled.items():
|
|
211
|
+
asset = rec.get("asset", "")
|
|
212
|
+
pat = rec.get("produced_at", 0)
|
|
213
|
+
# Guard: non-numeric produced_at cannot be compared (would TypeError).
|
|
214
|
+
# Treat it as 0 so numeric entries always win the newest comparison;
|
|
215
|
+
# the entry will still be candidate-winner only if it is the sole one
|
|
216
|
+
# for its asset — and it will then be dropped at the valid_until check.
|
|
217
|
+
if not isinstance(pat, (int, float)) or isinstance(pat, bool):
|
|
218
|
+
pat = 0
|
|
219
|
+
if asset not in newest or pat > newest[asset][0]:
|
|
220
|
+
newest[asset] = (pat, eid, rec)
|
|
221
|
+
|
|
222
|
+
# For each asset, the winner is re-queued if still valid; losers get dropped.
|
|
223
|
+
winners = {info[1] for info in newest.values()}
|
|
224
|
+
|
|
225
|
+
# Entries that are unsettled but NOT the newest for their asset -> dropped_superseded
|
|
226
|
+
for eid, rec in unsettled.items():
|
|
227
|
+
if eid not in winners:
|
|
228
|
+
self._append({"kind": "outcome", "id": eid, "outcome": "dropped_superseded"})
|
|
229
|
+
self._settled.add(eid)
|
|
230
|
+
|
|
231
|
+
# Re-queue winners: valid -> queue, expired or non-numeric -> dropped_expired
|
|
232
|
+
for asset, (pat, eid, rec) in newest.items():
|
|
233
|
+
valid_until = rec.get("valid_until", 0)
|
|
234
|
+
if not isinstance(valid_until, (int, float)) or isinstance(valid_until, bool):
|
|
235
|
+
# Non-numeric valid_until from a corrupt/poisoned persisted line.
|
|
236
|
+
# Drop it — do not attempt comparison (would TypeError).
|
|
237
|
+
_log("journal_corrupt_line", path=self._path, reason="valid_until_not_numeric", entry_id=eid)
|
|
238
|
+
self._append({"kind": "outcome", "id": eid, "outcome": "dropped_expired"})
|
|
239
|
+
self._settled.add(eid)
|
|
240
|
+
continue
|
|
241
|
+
if now_ms < valid_until:
|
|
242
|
+
signal = rec.get("signal", {})
|
|
243
|
+
entry = _Entry(id=eid, asset=asset, signal=signal, valid_until=valid_until)
|
|
244
|
+
self._queue[asset] = entry
|
|
245
|
+
else:
|
|
246
|
+
self._append({"kind": "outcome", "id": eid, "outcome": "dropped_expired"})
|
|
247
|
+
self._settled.add(eid)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Loop primitives: SIGALRM time-box, shutdown handlers, interruptible sleep,
|
|
2
|
+
and a tiny log_event.
|
|
3
|
+
|
|
4
|
+
Self-contained — no dependency on the old vendored senpi_runtime_helpers package.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import signal
|
|
9
|
+
import sys
|
|
10
|
+
import threading
|
|
11
|
+
import time
|
|
12
|
+
from contextlib import suppress
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _TickTimeout(BaseException):
|
|
16
|
+
"""Raised internally when a single tick exceeds its wall-clock budget."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def log_event(event: str, **fields) -> None:
|
|
20
|
+
"""Write a JSON lifecycle event to stderr with a [scaffold] prefix."""
|
|
21
|
+
record = {"event": event, "ts": time.time(), **fields}
|
|
22
|
+
print(f"[scaffold] {json.dumps(record)}", file=sys.stderr, flush=True)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _install_shutdown_handlers(stop_event: threading.Event) -> None:
|
|
26
|
+
"""Install SIGTERM and SIGINT handlers that set stop_event gracefully."""
|
|
27
|
+
def handler(signum: int, _frame: object) -> None:
|
|
28
|
+
if not stop_event.is_set():
|
|
29
|
+
log_event("scaffold_signal", signum=signum, action="graceful_shutdown_requested")
|
|
30
|
+
stop_event.set()
|
|
31
|
+
|
|
32
|
+
with suppress(ValueError): # only installable on the main thread
|
|
33
|
+
signal.signal(signal.SIGTERM, handler)
|
|
34
|
+
signal.signal(signal.SIGINT, handler)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _arm_tick_alarm(seconds: float) -> bool:
|
|
38
|
+
"""Arm SIGALRM to enforce per-tick wall-clock budget. Returns True if armed."""
|
|
39
|
+
if not hasattr(signal, "SIGALRM"):
|
|
40
|
+
return False
|
|
41
|
+
|
|
42
|
+
def alarm_handler(_signum: int, _frame: object) -> None:
|
|
43
|
+
raise _TickTimeout(f"tick exceeded {seconds:g}s")
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
signal.signal(signal.SIGALRM, alarm_handler)
|
|
47
|
+
signal.setitimer(signal.ITIMER_REAL, seconds)
|
|
48
|
+
return True
|
|
49
|
+
except (ValueError, OSError):
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _disarm_tick_alarm() -> None:
|
|
54
|
+
"""Disarm any pending SIGALRM timer."""
|
|
55
|
+
if hasattr(signal, "SIGALRM"):
|
|
56
|
+
with suppress(ValueError, OSError):
|
|
57
|
+
signal.setitimer(signal.ITIMER_REAL, 0)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _interruptible_sleep(seconds: float, stop_event: threading.Event) -> bool:
|
|
61
|
+
"""Sleep up to `seconds`, returning early if stop_event fires.
|
|
62
|
+
|
|
63
|
+
Returns True if the full sleep elapsed, False if woken early.
|
|
64
|
+
"""
|
|
65
|
+
return not stop_event.wait(seconds)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Runtime dependencies for the scaffold harness (src/scanners/external/scaffold/).
|
|
2
|
+
#
|
|
3
|
+
# The scaffold is shipped to the scanner box and run via `python3 -m scaffold`.
|
|
4
|
+
# `mcp` (the official Model Context Protocol Python SDK) backs ctx.senpi_mcp:
|
|
5
|
+
# `streamablehttp_client` + a single persistent `ClientSession` (see senpi_mcp.py).
|
|
6
|
+
# It is LAZY-IMPORTED at first use, so the package still imports where `mcp` is
|
|
7
|
+
# absent (e.g. unit tests inject a fake SDK) — install this on the box that runs
|
|
8
|
+
# scanners that call ctx.senpi_mcp.
|
|
9
|
+
#
|
|
10
|
+
# `mcp[cli]` is NOT needed — only the client transport + ClientSession surface.
|
|
11
|
+
mcp>=1.9.0
|