@bastani/atomic 0.9.11-alpha.6 → 0.9.11-alpha.8
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/CHANGELOG.md +38 -0
- package/README.md +3 -5
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/mcp/sampling-handler.ts +1 -5
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +1 -0
- package/dist/builtin/workflows/README.md +1 -1
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/skills/impeccable/SKILL.md +33 -129
- package/dist/builtin/workflows/skills/impeccable/agents/impeccable_asset_producer.toml +11 -3
- package/dist/builtin/workflows/skills/impeccable/agents/impeccable_documenter.toml +26 -0
- package/dist/builtin/workflows/skills/impeccable/agents/impeccable_finish_reviewer.toml +35 -0
- package/dist/builtin/workflows/skills/impeccable/reference/android.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/animate.md +72 -189
- package/dist/builtin/workflows/skills/impeccable/reference/audit.md +10 -9
- package/dist/builtin/workflows/skills/impeccable/reference/audit.native.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/bolder.md +19 -108
- package/dist/builtin/workflows/skills/impeccable/reference/clarify.md +59 -253
- package/dist/builtin/workflows/skills/impeccable/reference/colorize.md +51 -222
- package/dist/builtin/workflows/skills/impeccable/reference/craft-floor.md +45 -0
- package/dist/builtin/workflows/skills/impeccable/reference/craft.md +3 -121
- package/dist/builtin/workflows/skills/impeccable/reference/critique.md +28 -20
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/asset-producer.md +97 -0
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/documenter.md +23 -0
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/finish-reviewer.md +32 -0
- package/dist/builtin/workflows/skills/impeccable/reference/degraded/manual-edit-applier.md +92 -0
- package/dist/builtin/workflows/skills/impeccable/reference/delight.md +47 -279
- package/dist/builtin/workflows/skills/impeccable/reference/distill.md +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/doctor.md +53 -0
- package/dist/builtin/workflows/skills/impeccable/reference/document.md +60 -73
- package/dist/builtin/workflows/skills/impeccable/reference/harden.md +1 -12
- package/dist/builtin/workflows/skills/impeccable/reference/hooks.md +17 -4
- package/dist/builtin/workflows/skills/impeccable/reference/init.md +64 -163
- package/dist/builtin/workflows/skills/impeccable/reference/ios.md +1 -1
- package/dist/builtin/workflows/skills/impeccable/reference/layout.md +52 -153
- package/dist/builtin/workflows/skills/impeccable/reference/live.md +44 -32
- package/dist/builtin/workflows/skills/impeccable/reference/new-work.md +105 -0
- package/dist/builtin/workflows/skills/impeccable/reference/{product.md → operate.md} +6 -5
- package/dist/builtin/workflows/skills/impeccable/reference/optimize.md +4 -4
- package/dist/builtin/workflows/skills/impeccable/reference/overdrive.md +1 -4
- package/dist/builtin/workflows/skills/impeccable/reference/polish.md +68 -212
- package/dist/builtin/workflows/skills/impeccable/reference/quieter.md +3 -3
- package/dist/builtin/workflows/skills/impeccable/reference/routing.md +18 -0
- package/dist/builtin/workflows/skills/impeccable/reference/shape.md +38 -144
- package/dist/builtin/workflows/skills/impeccable/reference/typeset.md +48 -269
- package/dist/builtin/workflows/skills/impeccable/reference/visualize.md +38 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/command-metadata.json +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/concept-seed.mjs +584 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/context-signals.mjs +117 -9
- package/dist/builtin/workflows/skills/impeccable/scripts/context.mjs +486 -59
- package/dist/builtin/workflows/skills/impeccable/scripts/critique-storage.mjs +16 -45
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/browser/injected/index.mjs +96 -10
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/cli/main.mjs +143 -26
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/design-system.mjs +181 -12
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +3187 -182
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/browser/detect-url.mjs +102 -7
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +282 -70
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +183 -15
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/detect-html.mjs +22 -7
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/findings.mjs +7 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/node/file-system.mjs +16 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/registry/antipatterns.mjs +155 -42
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/rules/checks.mjs +2988 -155
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/constants.mjs +11 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/doctor.mjs +336 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/generate-image.mjs +232 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/hook-admin.mjs +90 -10
- package/dist/builtin/workflows/skills/impeccable/scripts/hook-lib.mjs +410 -78
- package/dist/builtin/workflows/skills/impeccable/scripts/hook.mjs +25 -8
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/artifact-schema.mjs +93 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/composition-catalog.mjs +165 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/concept-catalog.mjs +329 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-config.mjs +20 -5
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-paths.mjs +16 -8
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/provider.mjs +1 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness-deep.mjs +455 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness-notice.mjs +169 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness.mjs +457 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/surface-briefs.mjs +151 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/target-slug.mjs +33 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/lib/template-extensions.mjs +146 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/completion.mjs +10 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/live/event-validation.mjs +15 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/generation-preflight.mjs +149 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/poll-lanes.mjs +14 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/session-store.mjs +109 -32
- package/dist/builtin/workflows/skills/impeccable/scripts/live/source-lock.mjs +105 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/source-search.mjs +105 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live/sveltekit-adapter.mjs +8 -6
- package/dist/builtin/workflows/skills/impeccable/scripts/live/tanstack-adapter.mjs +280 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-accept.mjs +208 -68
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +563 -112
- package/dist/builtin/workflows/skills/impeccable/scripts/live-commit-manual-edits.mjs +3 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/live-inject.mjs +198 -13
- package/dist/builtin/workflows/skills/impeccable/scripts/live-insert.mjs +24 -6
- package/dist/builtin/workflows/skills/impeccable/scripts/live-manual-edit-evidence.mjs +6 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/live-poll.mjs +44 -14
- package/dist/builtin/workflows/skills/impeccable/scripts/live-server.mjs +398 -33
- package/dist/builtin/workflows/skills/impeccable/scripts/live-status.mjs +9 -5
- package/dist/builtin/workflows/skills/impeccable/scripts/live-wrap.mjs +81 -67
- package/dist/builtin/workflows/skills/impeccable/scripts/live.mjs +7 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/palette.mjs +76 -81
- package/dist/builtin/workflows/skills/impeccable/scripts/pin.mjs +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/serve-question.mjs +890 -0
- package/dist/builtin/workflows/skills/impeccable/scripts/surface-brief.mjs +74 -0
- package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +1 -24
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +232 -50
- package/dist/builtin/workflows/src/extension/workflow-model-catalog.ts +26 -0
- package/dist/builtin/workflows/src/extension/workflow-prompts.ts +3 -2
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-control.ts +23 -9
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts +1 -0
- package/dist/builtin/workflows/src/runs/foreground/postmortem-stage-chat.ts +20 -5
- package/dist/builtin/workflows/src/runs/foreground/stage-control-registry.ts +10 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-delivery-activity.ts +86 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-context.ts +6 -2
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +24 -18
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-send-user-message.ts +8 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-session-options.ts +3 -3
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-session.ts +2 -2
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-types.ts +16 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-delivery-activity.ts +121 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-live-events.ts +42 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-state.ts +16 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-types.ts +4 -0
- package/dist/cli/list-models.d.ts +2 -2
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +5 -5
- package/dist/cli/list-models.js.map +1 -1
- package/dist/core/agent-session-accessors.js +1 -1
- package/dist/core/agent-session-accessors.js.map +1 -1
- package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-auto-compaction.js +2 -5
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-compaction.js +1 -1
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +5 -5
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +4 -4
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-models.d.ts +1 -1
- package/dist/core/agent-session-models.d.ts.map +1 -1
- package/dist/core/agent-session-models.js +18 -14
- package/dist/core/agent-session-models.js.map +1 -1
- package/dist/core/agent-session-post-tool-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-post-tool-compaction.js +2 -4
- package/dist/core/agent-session-post-tool-compaction.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +3 -7
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-retry.js +1 -1
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-runtime-auth.d.ts +3 -3
- package/dist/core/agent-session-runtime-auth.d.ts.map +1 -1
- package/dist/core/agent-session-runtime-auth.js +4 -14
- package/dist/core/agent-session-runtime-auth.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +3 -3
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +3 -8
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +16 -23
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +2 -1
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +2 -2
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +2 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage-backends.d.ts +1 -0
- package/dist/core/auth-storage-backends.d.ts.map +1 -1
- package/dist/core/auth-storage-backends.js +18 -4
- package/dist/core/auth-storage-backends.js.map +1 -1
- package/dist/core/auth-storage.d.ts +12 -139
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +68 -374
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/copilot-env-routing.d.ts +36 -0
- package/dist/core/copilot-env-routing.d.ts.map +1 -0
- package/dist/core/copilot-env-routing.js +94 -0
- package/dist/core/copilot-env-routing.js.map +1 -0
- package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.js +10 -2
- package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
- package/dist/core/extensions/provider-types.d.ts +0 -40
- package/dist/core/extensions/provider-types.d.ts.map +1 -1
- package/dist/core/extensions/provider-types.js.map +1 -1
- package/dist/core/fallback-models.d.ts +4 -4
- package/dist/core/fallback-models.d.ts.map +1 -1
- package/dist/core/fallback-models.js +3 -3
- package/dist/core/fallback-models.js.map +1 -1
- package/dist/core/model-config.d.ts +542 -0
- package/dist/core/model-config.d.ts.map +1 -0
- package/dist/core/{model-registry-schemas.js → model-config.js} +85 -34
- package/dist/core/model-config.js.map +1 -0
- package/dist/core/model-registry.d.ts +25 -85
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +65 -388
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver-cli.d.ts +2 -2
- package/dist/core/model-resolver-cli.d.ts.map +1 -1
- package/dist/core/model-resolver-cli.js +2 -2
- package/dist/core/model-resolver-cli.js.map +1 -1
- package/dist/core/model-resolver-initial.d.ts +4 -4
- package/dist/core/model-resolver-initial.d.ts.map +1 -1
- package/dist/core/model-resolver-initial.js +17 -17
- package/dist/core/model-resolver-initial.js.map +1 -1
- package/dist/core/model-resolver-scope.d.ts +3 -3
- package/dist/core/model-resolver-scope.d.ts.map +1 -1
- package/dist/core/model-resolver-scope.js +4 -4
- package/dist/core/model-resolver-scope.js.map +1 -1
- package/dist/core/model-runtime-auth.d.ts +7 -0
- package/dist/core/model-runtime-auth.d.ts.map +1 -0
- package/dist/core/model-runtime-auth.js +14 -0
- package/dist/core/model-runtime-auth.js.map +1 -0
- package/dist/core/model-runtime-providers.d.ts +6 -0
- package/dist/core/model-runtime-providers.d.ts.map +1 -0
- package/dist/core/model-runtime-providers.js +22 -0
- package/dist/core/model-runtime-providers.js.map +1 -0
- package/dist/core/model-runtime-restoration.d.ts +6 -0
- package/dist/core/model-runtime-restoration.d.ts.map +1 -0
- package/dist/core/model-runtime-restoration.js +21 -0
- package/dist/core/model-runtime-restoration.js.map +1 -0
- package/dist/core/model-runtime-snapshot.d.ts +16 -0
- package/dist/core/model-runtime-snapshot.d.ts.map +1 -0
- package/dist/core/model-runtime-snapshot.js +52 -0
- package/dist/core/model-runtime-snapshot.js.map +1 -0
- package/dist/core/model-runtime-streaming.d.ts +17 -0
- package/dist/core/model-runtime-streaming.d.ts.map +1 -0
- package/dist/core/model-runtime-streaming.js +66 -0
- package/dist/core/model-runtime-streaming.js.map +1 -0
- package/dist/core/model-runtime-types.d.ts +21 -0
- package/dist/core/model-runtime-types.d.ts.map +1 -0
- package/dist/core/model-runtime-types.js +2 -0
- package/dist/core/model-runtime-types.js.map +1 -0
- package/dist/core/model-runtime.d.ts +50 -29
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +330 -90
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/models-store.d.ts +2 -10
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +2 -29
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/oauth-login.d.ts +24 -0
- package/dist/core/oauth-login.d.ts.map +1 -0
- package/dist/core/oauth-login.js +87 -0
- package/dist/core/oauth-login.js.map +1 -0
- package/dist/core/oauth-provider-metadata.d.ts +5 -0
- package/dist/core/oauth-provider-metadata.d.ts.map +1 -0
- package/dist/core/oauth-provider-metadata.js +19 -0
- package/dist/core/oauth-provider-metadata.js.map +1 -0
- package/dist/core/provider-composer-internal.d.ts +53 -0
- package/dist/core/provider-composer-internal.d.ts.map +1 -0
- package/dist/core/provider-composer-internal.js +273 -0
- package/dist/core/provider-composer-internal.js.map +1 -0
- package/dist/core/provider-composer.d.ts +16 -0
- package/dist/core/provider-composer.d.ts.map +1 -0
- package/dist/core/provider-composer.js +108 -0
- package/dist/core/provider-composer.js.map +1 -0
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +74 -122
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resolve-config-value.d.ts +8 -7
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js +26 -23
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +16 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -0
- package/dist/core/runtime-credentials.js +42 -0
- package/dist/core/runtime-credentials.js.map +1 -0
- package/dist/core/sdk-types.d.ts +1 -7
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +27 -28
- package/dist/core/sdk.js.map +1 -1
- package/dist/extensions/llama/index.js +1 -1
- package/dist/extensions/llama/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts +2 -4
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +25 -17
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/main-runtime-api-key.d.ts +6 -0
- package/dist/main-runtime-api-key.d.ts.map +1 -0
- package/dist/main-runtime-api-key.js +6 -0
- package/dist/main-runtime-api-key.js.map +1 -0
- package/dist/main-session-options.d.ts +2 -2
- package/dist/main-session-options.d.ts.map +1 -1
- package/dist/main-session-options.js +3 -3
- package/dist/main-session-options.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +9 -11
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.js +2 -14
- package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.js +9 -0
- package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts +25 -0
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-runtime.js +53 -0
- package/dist/modes/interactive/components/chat-session-host-runtime.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts +13 -0
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +22 -1
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +1 -3
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +4 -3
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +56 -73
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +4 -3
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +15 -24
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +10 -4
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.js +20 -31
- package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-routing.d.ts +1 -1
- package/dist/modes/interactive/interactive-auth-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-auth-routing.js +21 -47
- package/dist/modes/interactive/interactive-auth-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.js +3 -3
- package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.js +8 -8
- package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.js +2 -1
- package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-model-catalog-startup.js +2 -2
- package/dist/modes/interactive/interactive-model-catalog-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.js +11 -11
- package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +1 -1
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +2 -2
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +1 -1
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-auth.d.ts +2 -2
- package/dist/modes/interactive-engine/isolated-auth.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-auth.js +4 -3
- package/dist/modes/interactive-engine/isolated-auth.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +4 -3
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/remote-model-catalog.d.ts +0 -1
- package/dist/modes/interactive-engine/remote-model-catalog.d.ts.map +1 -1
- package/dist/modes/interactive-engine/remote-model-catalog.js +11 -50
- package/dist/modes/interactive-engine/remote-model-catalog.js.map +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +2 -2
- package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-api.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +26 -19
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-oauth-client.d.ts +1 -1
- package/dist/modes/rpc/rpc-oauth-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-oauth-client.js +1 -1
- package/dist/modes/rpc/rpc-oauth-client.js.map +1 -1
- package/dist/modes/rpc/rpc-oauth-interaction.d.ts +1 -1
- package/dist/modes/rpc/rpc-oauth-interaction.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-oauth-interaction.js +1 -1
- package/dist/modes/rpc/rpc-oauth-interaction.js.map +1 -1
- package/dist/modes/rpc/rpc-provider-auth.d.ts +4 -5
- package/dist/modes/rpc/rpc-provider-auth.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-provider-auth.js +19 -66
- package/dist/modes/rpc/rpc-provider-auth.js.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.js +1 -1
- package/dist/modes/rpc/rpc-session-binding.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +7 -4
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +5 -7
- package/dist/package-manager-cli.js.map +1 -1
- package/docs/changelog.mdx +1 -1
- package/docs/custom-provider.md +1 -1
- package/docs/models.md +4 -6
- package/docs/providers.md +13 -0
- package/docs/quickstart.md +2 -1
- package/docs/sdk.md +32 -49
- package/docs/tui.md +7 -2
- package/docs/workflows.md +4 -4
- package/examples/sdk/02-custom-model.ts +8 -10
- package/examples/sdk/09-api-keys-and-oauth.ts +17 -23
- package/examples/sdk/12-full-control.ts +9 -11
- package/examples/sdk/README.md +17 -21
- package/npm-shrinkwrap.json +23 -23
- package/package.json +2 -2
- package/dist/builtin/workflows/skills/impeccable/reference/brand.md +0 -108
- package/dist/builtin/workflows/skills/impeccable/reference/codex.md +0 -105
- package/dist/builtin/workflows/skills/impeccable/reference/interaction-design.md +0 -189
- package/dist/core/model-registry-auth.d.ts +0 -10
- package/dist/core/model-registry-auth.d.ts.map +0 -1
- package/dist/core/model-registry-auth.js +0 -98
- package/dist/core/model-registry-auth.js.map +0 -1
- package/dist/core/model-registry-builtins.d.ts +0 -8
- package/dist/core/model-registry-builtins.d.ts.map +0 -1
- package/dist/core/model-registry-builtins.js +0 -104
- package/dist/core/model-registry-builtins.js.map +0 -1
- package/dist/core/model-registry-custom-loader.d.ts +0 -3
- package/dist/core/model-registry-custom-loader.d.ts.map +0 -1
- package/dist/core/model-registry-custom-loader.js +0 -255
- package/dist/core/model-registry-custom-loader.js.map +0 -1
- package/dist/core/model-registry-dynamic.d.ts +0 -7
- package/dist/core/model-registry-dynamic.d.ts.map +0 -1
- package/dist/core/model-registry-dynamic.js +0 -189
- package/dist/core/model-registry-dynamic.js.map +0 -1
- package/dist/core/model-registry-extension-refresh.d.ts +0 -23
- package/dist/core/model-registry-extension-refresh.d.ts.map +0 -1
- package/dist/core/model-registry-extension-refresh.js +0 -32
- package/dist/core/model-registry-extension-refresh.js.map +0 -1
- package/dist/core/model-registry-loader.d.ts +0 -5
- package/dist/core/model-registry-loader.d.ts.map +0 -1
- package/dist/core/model-registry-loader.js +0 -29
- package/dist/core/model-registry-loader.js.map +0 -1
- package/dist/core/model-registry-schemas.d.ts +0 -1399
- package/dist/core/model-registry-schemas.d.ts.map +0 -1
- package/dist/core/model-registry-schemas.js.map +0 -1
- package/dist/core/model-registry-types.d.ts +0 -91
- package/dist/core/model-registry-types.d.ts.map +0 -1
- package/dist/core/model-registry-types.js +0 -2
- package/dist/core/model-registry-types.js.map +0 -1
- package/dist/core/model-registry-validation.d.ts +0 -7
- package/dist/core/model-registry-validation.d.ts.map +0 -1
- package/dist/core/model-registry-validation.js +0 -12
- package/dist/core/model-registry-validation.js.map +0 -1
- package/dist/core/oauth-compat.d.ts +0 -17
- package/dist/core/oauth-compat.d.ts.map +0 -1
- package/dist/core/oauth-compat.js +0 -2
- package/dist/core/oauth-compat.js.map +0 -1
- package/dist/core/oauth-provider-bridge.d.ts +0 -63
- package/dist/core/oauth-provider-bridge.d.ts.map +0 -1
- package/dist/core/oauth-provider-bridge.js +0 -232
- package/dist/core/oauth-provider-bridge.js.map +0 -1
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Impeccable design hook — PostToolUse entry point.
|
|
3
|
+
* Impeccable design hook — PostToolUse + Stop entry point.
|
|
4
4
|
*
|
|
5
|
-
* Reads the Claude Code, Codex, or GitHub Copilot hook event from stdin
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Reads the Claude Code, Codex, or GitHub Copilot hook event from stdin and routes by
|
|
6
|
+
* `hook_event_name`:
|
|
7
|
+
*
|
|
8
|
+
* - PostToolUse: runs the immediate-tier detector rules against the touched
|
|
9
|
+
* file and emits a system reminder via
|
|
10
|
+
* `hookSpecificOutput.additionalContext` when findings exist.
|
|
11
|
+
* - Stop: runs the FULL detector rule set over every UI file touched this
|
|
12
|
+
* session (the deep pass), deduped against what the per-edit pass already
|
|
13
|
+
* surfaced, and emits once via the Stop additionalContext channel.
|
|
8
14
|
*
|
|
9
15
|
* Contract: never break a turn. Always exit 0. Clean files emit a small ack
|
|
10
|
-
* unless quiet mode is enabled.
|
|
16
|
+
* unless quiet mode is enabled; a clean Stop pass is silent.
|
|
11
17
|
*
|
|
12
18
|
* Most logic lives in `hook-lib.mjs` so it is unit-testable without a
|
|
13
19
|
* subprocess. This file is the thin stdin/stdout adapter.
|
|
14
20
|
*/
|
|
15
21
|
|
|
16
|
-
import { runHook, writeAuditLog } from './hook-lib.mjs';
|
|
22
|
+
import { runHook, runStopHook, writeAuditLog } from './hook-lib.mjs';
|
|
17
23
|
|
|
18
24
|
async function readStdin() {
|
|
19
25
|
if (process.stdin.isTTY) return '';
|
|
@@ -22,6 +28,16 @@ async function readStdin() {
|
|
|
22
28
|
return Buffer.concat(chunks).toString('utf-8');
|
|
23
29
|
}
|
|
24
30
|
|
|
31
|
+
function isStopEvent(stdinJson) {
|
|
32
|
+
try {
|
|
33
|
+
const event = JSON.parse(stdinJson);
|
|
34
|
+
return event && typeof event === 'object' && event.hook_event_name === 'Stop';
|
|
35
|
+
} catch {
|
|
36
|
+
// Malformed stdin falls through to runHook, which audits the skip.
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
25
41
|
async function main() {
|
|
26
42
|
// Snapshot the inherited env FIRST so the re-entrancy guard checks the
|
|
27
43
|
// parent's value, not the value we are about to export for any child
|
|
@@ -32,7 +48,8 @@ async function main() {
|
|
|
32
48
|
let stdinJson = '';
|
|
33
49
|
try { stdinJson = await readStdin(); } catch { /* fall through */ }
|
|
34
50
|
|
|
35
|
-
const
|
|
51
|
+
const run = isStopEvent(stdinJson) ? runStopHook : runHook;
|
|
52
|
+
const result = await run({
|
|
36
53
|
stdinJson,
|
|
37
54
|
env: inheritedEnv,
|
|
38
55
|
cwd: process.cwd(),
|
|
@@ -50,7 +67,7 @@ main().catch((err) => {
|
|
|
50
67
|
try {
|
|
51
68
|
writeAuditLog(process.env, {
|
|
52
69
|
ts: new Date().toISOString(),
|
|
53
|
-
event: '
|
|
70
|
+
event: 'hook-error',
|
|
54
71
|
error: String(err && err.message ? err.message : err),
|
|
55
72
|
});
|
|
56
73
|
} catch { /* swallow */ }
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema versions for the artifacts Impeccable writes, plus the readers and
|
|
3
|
+
* writers for the PRODUCT.md provenance stamp.
|
|
4
|
+
*
|
|
5
|
+
* Why schema versions rather than the skill version: a PRODUCT.md written by
|
|
6
|
+
* v4.0.0 is not stale under v4.0.1, so stamping the release version would make
|
|
7
|
+
* every artifact "old" on every patch. A schema version changes only when the
|
|
8
|
+
* shape changes, which is exactly when a migration is owed. It also gives the
|
|
9
|
+
* writing flows a literal constant to copy instead of a value they would have
|
|
10
|
+
* to look up.
|
|
11
|
+
*
|
|
12
|
+
* DESIGN.md deliberately carries no stamp. It follows the external
|
|
13
|
+
* design.md spec that Stitch's linter validates, and an extra frontmatter key
|
|
14
|
+
* risks failing that lint for no gain: every DESIGN.md staleness signal
|
|
15
|
+
* (sidecar schema version, sidecar mtime, section coverage, git drift) is
|
|
16
|
+
* measurable without one.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** PRODUCT.md as init.md writes it today: the ten-section v4 record. */
|
|
20
|
+
export const PRODUCT_SCHEMA_VERSION = 1;
|
|
21
|
+
|
|
22
|
+
/** `.impeccable/design.json`, as documented in reference/document.md Step 4b. */
|
|
23
|
+
export const DESIGN_SIDECAR_SCHEMA_VERSION = 2;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Sections init.md added in v4. A PRODUCT.md carrying none of them, and no
|
|
27
|
+
* stamp, predates the current record. Used only as a fallback: an explicit
|
|
28
|
+
* stamp always wins.
|
|
29
|
+
*/
|
|
30
|
+
export const PRODUCT_V4_SECTIONS = Object.freeze([
|
|
31
|
+
'Positioning',
|
|
32
|
+
'Operating Context',
|
|
33
|
+
'Evidence on Hand',
|
|
34
|
+
'Product Principles',
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Headings Impeccable used to read and no longer does, with the reason. The
|
|
39
|
+
* agent needs the reason: told only that a field is deprecated it tends to
|
|
40
|
+
* preserve it "just in case", which is how a v3 register value keeps steering
|
|
41
|
+
* v4 output.
|
|
42
|
+
*/
|
|
43
|
+
export const PRODUCT_DEPRECATED_SECTIONS = Object.freeze({
|
|
44
|
+
Register: 'v4 replaced the brand/product register axis with the four visitor modes '
|
|
45
|
+
+ '(Persuade, Operate, Read, Experience), which are chosen per surface and persisted in that '
|
|
46
|
+
+ "surface's brief. Nothing reads `## Register` any more.",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const PRODUCT_STAMP_RE = /^[ \t]*<!--[ \t]*impeccable:product-schema[ \t]+(\d+)[ \t]*-->[ \t]*$/im;
|
|
50
|
+
|
|
51
|
+
/** The literal stamp line, for the init template and for migrations. */
|
|
52
|
+
export function productStampLine(version = PRODUCT_SCHEMA_VERSION) {
|
|
53
|
+
return `<!-- impeccable:product-schema ${version} -->`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Schema version stamped in a PRODUCT.md body, or null when unstamped. Null
|
|
58
|
+
* means "written before stamping existed", not "invalid".
|
|
59
|
+
*/
|
|
60
|
+
export function readProductSchemaVersion(markdown) {
|
|
61
|
+
const match = String(markdown || '').match(PRODUCT_STAMP_RE);
|
|
62
|
+
if (!match) return null;
|
|
63
|
+
const version = Number.parseInt(match[1], 10);
|
|
64
|
+
return Number.isInteger(version) ? version : null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Add or update the stamp, returning the new body. Idempotent. A stamped file
|
|
69
|
+
* keeps the stamp where it already sits so a migration never reorders the
|
|
70
|
+
* user's prose; an unstamped file gets it directly under the leading `#`
|
|
71
|
+
* heading, or at the top when there is none.
|
|
72
|
+
*/
|
|
73
|
+
export function stampProductSchema(markdown, version = PRODUCT_SCHEMA_VERSION) {
|
|
74
|
+
const body = String(markdown || '');
|
|
75
|
+
const line = productStampLine(version);
|
|
76
|
+
if (PRODUCT_STAMP_RE.test(body)) return body.replace(PRODUCT_STAMP_RE, line);
|
|
77
|
+
|
|
78
|
+
const lines = body.split('\n');
|
|
79
|
+
const headingIndex = lines.findIndex((entry) => /^#\s+\S/.test(entry));
|
|
80
|
+
if (headingIndex === -1) return `${line}\n\n${body.replace(/^\n+/, '')}`;
|
|
81
|
+
lines.splice(headingIndex + 1, 0, '', line);
|
|
82
|
+
return lines.join('\n');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Schema version of a parsed design.json. Returns null for a missing or
|
|
87
|
+
* non-numeric field, which is how schemaVersion-1-era sidecars present
|
|
88
|
+
* (the field predates the v2 rewrite in some files).
|
|
89
|
+
*/
|
|
90
|
+
export function readSidecarSchemaVersion(sidecar) {
|
|
91
|
+
const version = sidecar && typeof sidecar === 'object' ? sidecar.schemaVersion : null;
|
|
92
|
+
return Number.isInteger(version) ? version : null;
|
|
93
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { CONCEPT_STATUSES, normalizeConceptForm } from './concept-catalog.mjs';
|
|
4
|
+
|
|
5
|
+
// Catalog B: stagings rather than styles. A composition organizes attention,
|
|
6
|
+
// sequence, or manipulation on a surface and must survive being dressed in
|
|
7
|
+
// any committed visual identity; it deliberately carries no palette or type
|
|
8
|
+
// half. Surface-scope seeds draw from here (plus catalog A duals); direction
|
|
9
|
+
// seeds pair one composition with a chosen world for the first surface.
|
|
10
|
+
|
|
11
|
+
export const COMPOSITION_GRAMMAR_PREFIXES = [
|
|
12
|
+
'Staging/hierarchy:',
|
|
13
|
+
'Sequence/attention:',
|
|
14
|
+
'Controls/state:',
|
|
15
|
+
'Adaptation:',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
// Surfaces align with the skill's modes: a persuade staging and an operate
|
|
19
|
+
// staging are different species, and read/experience surfaces get their own.
|
|
20
|
+
export const COMPOSITION_SURFACES = new Set(['persuade', 'operate', 'read', 'experience']);
|
|
21
|
+
|
|
22
|
+
export function compositionContentHash(composition) {
|
|
23
|
+
const payload = [
|
|
24
|
+
composition?.form ?? '',
|
|
25
|
+
composition?.lineage ?? '',
|
|
26
|
+
JSON.stringify(composition?.tags ?? []),
|
|
27
|
+
JSON.stringify(composition?.grammar ?? []),
|
|
28
|
+
composition?.spark ?? '',
|
|
29
|
+
composition?.webLeverage ?? '',
|
|
30
|
+
].join('\n');
|
|
31
|
+
return crypto.createHash('sha256').update(payload).digest('hex').slice(0, 12);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function validateCompositionEntry(composition, { existingForms = new Map() } = {}) {
|
|
35
|
+
const errors = [];
|
|
36
|
+
const id = composition?.id || '(unknown)';
|
|
37
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(composition?.id || '')) {
|
|
38
|
+
errors.push(`invalid composition id: ${String(composition?.id)}`);
|
|
39
|
+
}
|
|
40
|
+
const normalized = normalizeConceptForm(composition?.form);
|
|
41
|
+
if (!normalized) {
|
|
42
|
+
errors.push(`composition ${id} needs a form`);
|
|
43
|
+
} else if (existingForms.has(normalized)) {
|
|
44
|
+
errors.push(`duplicate composition form: ${id} and ${existingForms.get(normalized)}`);
|
|
45
|
+
}
|
|
46
|
+
if (typeof composition?.form !== 'string'
|
|
47
|
+
|| composition.form.trim().length < 40
|
|
48
|
+
|| composition.form.trim().length > 360
|
|
49
|
+
|| !composition.form.includes(',')) {
|
|
50
|
+
errors.push(`composition ${id} must name a staging and its structural mechanism after a comma`);
|
|
51
|
+
}
|
|
52
|
+
if (typeof composition?.lineage !== 'string'
|
|
53
|
+
|| composition.lineage.trim().length < 12
|
|
54
|
+
|| composition.lineage.trim().length > 200) {
|
|
55
|
+
errors.push(`composition ${id} needs lineage metadata of 12–200 characters`);
|
|
56
|
+
}
|
|
57
|
+
if (!COMPOSITION_SURFACES.has(composition?.surface)) {
|
|
58
|
+
errors.push(`composition ${id} needs a surface of ${[...COMPOSITION_SURFACES].join(', ')}`);
|
|
59
|
+
}
|
|
60
|
+
if (!Array.isArray(composition?.tags)
|
|
61
|
+
|| composition.tags.length !== 3
|
|
62
|
+
|| composition.tags.some(tag => typeof tag !== 'string' || !tag.trim())) {
|
|
63
|
+
errors.push(`composition ${id} must have exactly three structural tags`);
|
|
64
|
+
}
|
|
65
|
+
if (!Array.isArray(composition?.grammar)
|
|
66
|
+
|| composition.grammar.length !== COMPOSITION_GRAMMAR_PREFIXES.length
|
|
67
|
+
|| composition.grammar.some(rule => typeof rule !== 'string' || rule.trim().length < 12 || rule.trim().length > 180)) {
|
|
68
|
+
errors.push(`composition ${id} needs grammar with exactly four rules of 12–180 characters`);
|
|
69
|
+
} else {
|
|
70
|
+
const unique = new Set(composition.grammar.map(normalizeConceptForm));
|
|
71
|
+
if (unique.size !== COMPOSITION_GRAMMAR_PREFIXES.length) {
|
|
72
|
+
errors.push(`composition ${id} has duplicate grammar rules`);
|
|
73
|
+
}
|
|
74
|
+
if (composition.grammar.some((rule, index) => !rule.startsWith(COMPOSITION_GRAMMAR_PREFIXES[index]))) {
|
|
75
|
+
errors.push(`composition ${id} grammar must use staging, sequence, controls, and adaptation prefixes in order`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (typeof composition?.spark !== 'string'
|
|
79
|
+
|| composition.spark.trim().length < 80
|
|
80
|
+
|| composition.spark.trim().length > 320) {
|
|
81
|
+
errors.push(`composition ${id} needs a vivid spark of 80–320 characters`);
|
|
82
|
+
}
|
|
83
|
+
if (typeof composition?.webLeverage !== 'string'
|
|
84
|
+
|| composition.webLeverage.trim().length < 20
|
|
85
|
+
|| composition.webLeverage.trim().length > 240) {
|
|
86
|
+
errors.push(`composition ${id} needs web leverage of 20–240 characters`);
|
|
87
|
+
}
|
|
88
|
+
return errors;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function readCompositionCatalog(catalogPath, reviewsPath) {
|
|
92
|
+
const catalog = JSON.parse(readFileSync(catalogPath, 'utf8'));
|
|
93
|
+
const reviewData = JSON.parse(readFileSync(reviewsPath, 'utf8'));
|
|
94
|
+
const reviews = reviewData.reviews || {};
|
|
95
|
+
const familiesById = new Map((catalog.families || []).map(family => [family.id, family]));
|
|
96
|
+
const compositions = (catalog.compositions || []).map(composition => ({
|
|
97
|
+
...composition,
|
|
98
|
+
familyLabel: familiesById.get(composition.familyId)?.label || null,
|
|
99
|
+
status: reviews[composition.id]?.status || 'pending',
|
|
100
|
+
review: reviews[composition.id] || null,
|
|
101
|
+
}));
|
|
102
|
+
return { catalog, reviewData, reviews, compositions };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function validateCompositionCatalog(catalog, reviewData, { minimumTotal } = {}) {
|
|
106
|
+
const errors = [];
|
|
107
|
+
const familyIds = new Set();
|
|
108
|
+
const ids = new Set();
|
|
109
|
+
const forms = new Map();
|
|
110
|
+
|
|
111
|
+
if (!Number.isInteger(catalog?.schemaVersion) || catalog.schemaVersion < 1) {
|
|
112
|
+
errors.push('composition catalog schemaVersion must be a positive integer');
|
|
113
|
+
}
|
|
114
|
+
if (typeof catalog?.qualityBar?.principle !== 'string' || catalog.qualityBar.principle.trim().length < 80) {
|
|
115
|
+
errors.push('composition qualityBar.principle must define the staging bar');
|
|
116
|
+
}
|
|
117
|
+
if (!Array.isArray(catalog?.families) || catalog.families.length < 4) {
|
|
118
|
+
errors.push('composition catalog needs at least four families');
|
|
119
|
+
}
|
|
120
|
+
for (const family of catalog?.families || []) {
|
|
121
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(family.id || '')) errors.push(`invalid composition family id: ${String(family.id)}`);
|
|
122
|
+
if (familyIds.has(family.id)) errors.push(`duplicate composition family id: ${family.id}`);
|
|
123
|
+
familyIds.add(family.id);
|
|
124
|
+
if (typeof family.description !== 'string' || family.description.trim().length < 40) {
|
|
125
|
+
errors.push(`composition family ${family.id || '(unknown)'} needs a description`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const composition of catalog?.compositions || []) {
|
|
129
|
+
if (ids.has(composition.id)) errors.push(`duplicate composition id: ${composition.id}`);
|
|
130
|
+
ids.add(composition.id);
|
|
131
|
+
if (!familyIds.has(composition.familyId)) {
|
|
132
|
+
errors.push(`composition ${composition.id} must belong to a declared family, got: ${String(composition.familyId)}`);
|
|
133
|
+
}
|
|
134
|
+
errors.push(...validateCompositionEntry(composition, { existingForms: forms }));
|
|
135
|
+
const normalized = normalizeConceptForm(composition.form);
|
|
136
|
+
if (normalized) forms.set(normalized, composition.id);
|
|
137
|
+
}
|
|
138
|
+
if (minimumTotal !== undefined && (catalog?.compositions || []).length < minimumTotal) {
|
|
139
|
+
errors.push(`expected at least ${minimumTotal} compositions, found ${(catalog?.compositions || []).length}`);
|
|
140
|
+
}
|
|
141
|
+
for (const [id, review] of Object.entries(reviewData?.reviews || {})) {
|
|
142
|
+
if (!ids.has(id)) errors.push(`composition review references missing entry: ${id}`);
|
|
143
|
+
if (!CONCEPT_STATUSES.has(review?.status)) errors.push(`invalid composition review status for ${id}`);
|
|
144
|
+
if (typeof review?.formHash !== 'string' || !review.formHash.trim()) {
|
|
145
|
+
errors.push(`composition review ${id} needs a formHash`);
|
|
146
|
+
} else {
|
|
147
|
+
const entry = (catalog?.compositions || []).find(composition => composition.id === id);
|
|
148
|
+
if (entry && review.formHash !== compositionContentHash(entry)) {
|
|
149
|
+
errors.push(`composition review ${id} is stale: content changed since review`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (review?.note !== undefined && (typeof review.note !== 'string' || !review.note.trim() || review.note.length > 500)) {
|
|
153
|
+
errors.push(`composition review ${id} note must be a non-empty string of 500 characters or fewer`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
errors,
|
|
158
|
+
stats: {
|
|
159
|
+
families: familyIds.size,
|
|
160
|
+
compositions: (catalog?.compositions || []).length,
|
|
161
|
+
approved: Object.values(reviewData?.reviews || {}).filter(review => review?.status === 'approved').length,
|
|
162
|
+
rejected: Object.values(reviewData?.reviews || {}).filter(review => review?.status === 'rejected').length,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
|
|
4
|
+
export const CONCEPT_STATUSES = new Set(['approved', 'rejected']);
|
|
5
|
+
|
|
6
|
+
// What a concept is actually strong at. Worlds carry a durable visual
|
|
7
|
+
// identity (their palette/type half is the magnet); compositions carry a
|
|
8
|
+
// staging or interaction idea (their topology half is the magnet) that can be
|
|
9
|
+
// dressed in any committed identity; duals fuse both inseparably. Direction
|
|
10
|
+
// seeds draw world|dual, surface seeds draw composition|dual.
|
|
11
|
+
export const CONCEPT_STRENGTHS = new Set(['world', 'composition', 'dual']);
|
|
12
|
+
|
|
13
|
+
// Challenger tiers, ordered by translation cost: graphic grammars map to
|
|
14
|
+
// interface almost directly, instrument languages carry interaction physics,
|
|
15
|
+
// atmosphere worlds need the largest translation step. Every seed roll draws
|
|
16
|
+
// one challenger from each tier so at least one directly-usable graphic
|
|
17
|
+
// system is always on the table.
|
|
18
|
+
export const WELL_TIERS = ['graphic', 'interaction', 'atmosphere'];
|
|
19
|
+
|
|
20
|
+
const WEB_LEVERAGE_RE = /(?:\b3d\b|\badaptive\b|\banimat(?:e|ed|ion)\b|\bapi\b|\baria\b|\baudio\b|\bautomated?\b|\bbarcode\b|\bbroadcastchannel\b|\bbrowser\b|\bcamera\b|canvas\b|\bcaption\b|\bcollaborat(?:e|ive|ion)\b|\bcompar(?:e|ison)\b|\bcomput(?:e|ed|ation)\b|\bcomputer[- ]vision\b|\bconstraint[- ]solving\b|\bcryptographic?\b|\bcss\b|\bdeep[- ]link(?:ing)?\b|\bdirect manipulation\b|\bdom\b|\bdrag\b|\bfilter\b|\bfocus\b|\bgenerative\b|\bgeolocat(?:e|ed|ion)\b|\bgesture\b|\bgpu\b|\bgraph\b|\bhistory\b|\bindexeddb\b|\binteractive\b|\bintersectionobserver\b|\bkeyboard\b|\blive\b|\blocal\b|\bmicrophone\b|\bmotion\b|\bmultiplayer\b|\bnative\b|\bnotification\b|\boffline\b|\bpersonaliz(?:e|ed|ation)\b|\bplayable\b|\bpointer\b|\bprocedural\b|\bprovenance\b|\breal[- ]?time\b|\bresizeobserver\b|\bresponsive\b|\breveal\b|\bscrub\b|\bsearch\b|\bsearchparams\b|\bsensor\b|\bserver[- ]sent\b|\bservice worker\b|\bshader\b|\bsimulat(?:e|ed|ion|or)\b|\bspatial\b|\bstate\b|\bstream(?:ing)?\b|\bsvg\b|\bsynchroniz(?:e|ed|ation)\b|\btimeline\b|\btouch\b|\burl|\bvideo\b|\bweb(?:gl|socket|vtt)?\b|\bworker\b|\bzoom\b)/i;
|
|
21
|
+
export const SYSTEM_PREFIXES = [
|
|
22
|
+
'Palette/material:',
|
|
23
|
+
'Type/composition:',
|
|
24
|
+
'Topology/navigation:',
|
|
25
|
+
'Controls/state:',
|
|
26
|
+
'Responsive/motion:',
|
|
27
|
+
];
|
|
28
|
+
const BLAND_FORM_RE = /\b(?:control room|command center|operations center|dispatch desk|review queue|speaker queue|management console|admin console|operator loop|coordination system|tracking system|planning system|software platform|digital platform|operations cockpit|app portal|web portal|data hub|dashboard|workflow|planner|tracker|orchestrator)\b/i;
|
|
29
|
+
|
|
30
|
+
export function normalizeConceptForm(value) {
|
|
31
|
+
return String(value || '')
|
|
32
|
+
.normalize('NFKD')
|
|
33
|
+
.toLowerCase()
|
|
34
|
+
.replace(/[’‘]/g, "'")
|
|
35
|
+
.replace(/[^a-z0-9]+/g, ' ')
|
|
36
|
+
.trim();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function validateConceptEntry(concept, { existingForms = new Map() } = {}) {
|
|
40
|
+
const errors = [];
|
|
41
|
+
const id = concept?.id || '(unknown)';
|
|
42
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(concept?.id || '')) {
|
|
43
|
+
errors.push(`invalid concept id: ${String(concept?.id)}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const normalized = normalizeConceptForm(concept?.form);
|
|
47
|
+
if (!normalized) {
|
|
48
|
+
errors.push(`concept ${id} needs a form`);
|
|
49
|
+
} else if (existingForms.has(normalized)) {
|
|
50
|
+
errors.push(`duplicate concept form: ${id} and ${existingForms.get(normalized)}`);
|
|
51
|
+
}
|
|
52
|
+
if (typeof concept?.form !== 'string'
|
|
53
|
+
|| concept.form.trim().length < 40
|
|
54
|
+
|| concept.form.trim().length > 360
|
|
55
|
+
|| !concept.form.includes(',')) {
|
|
56
|
+
errors.push(`concept ${id} must name a form and inherited structure after a comma`);
|
|
57
|
+
}
|
|
58
|
+
if (typeof concept?.lineage !== 'string'
|
|
59
|
+
|| concept.lineage.trim().length < 12
|
|
60
|
+
|| concept.lineage.trim().length > 200) {
|
|
61
|
+
errors.push(`concept ${id} needs specific lineage metadata of 12–200 characters`);
|
|
62
|
+
}
|
|
63
|
+
if (!CONCEPT_STRENGTHS.has(concept?.strength)) {
|
|
64
|
+
errors.push(`concept ${id} needs a strength of ${[...CONCEPT_STRENGTHS].join(', ')}`);
|
|
65
|
+
}
|
|
66
|
+
if (!Array.isArray(concept?.tags)
|
|
67
|
+
|| concept.tags.length !== 3
|
|
68
|
+
|| concept.tags.some(tag => typeof tag !== 'string' || !tag.trim())) {
|
|
69
|
+
errors.push(`concept ${id} must have exactly three structural tags`);
|
|
70
|
+
}
|
|
71
|
+
if (!Array.isArray(concept?.system)
|
|
72
|
+
|| concept.system.length !== SYSTEM_PREFIXES.length
|
|
73
|
+
|| concept.system.some(rule => typeof rule !== 'string' || rule.trim().length < 12 || rule.trim().length > 180)) {
|
|
74
|
+
errors.push(`concept ${id} needs system grammar with exactly five rules of 12–180 characters`);
|
|
75
|
+
} else {
|
|
76
|
+
const uniqueRules = new Set(concept.system.map(normalizeConceptForm));
|
|
77
|
+
if (uniqueRules.size !== SYSTEM_PREFIXES.length) {
|
|
78
|
+
errors.push(`concept ${id} has duplicate system grammar rules`);
|
|
79
|
+
}
|
|
80
|
+
if (concept.system.some((rule, index) => !rule.startsWith(SYSTEM_PREFIXES[index]))) {
|
|
81
|
+
errors.push(`concept ${id} system grammar must use palette, type, topology, controls, and responsive prefixes in order`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (typeof concept?.spark !== 'string'
|
|
85
|
+
|| concept.spark.trim().length < 80
|
|
86
|
+
|| concept.spark.trim().length > 320) {
|
|
87
|
+
errors.push(`concept ${id} needs a vivid creative spark of 80–320 characters`);
|
|
88
|
+
}
|
|
89
|
+
if (typeof concept?.webLeverage !== 'string'
|
|
90
|
+
|| concept.webLeverage.trim().length < 20
|
|
91
|
+
|| concept.webLeverage.trim().length > 240) {
|
|
92
|
+
errors.push(`concept ${id} needs web leverage of 20–240 characters`);
|
|
93
|
+
}
|
|
94
|
+
if (/\b(?:live digital system|shared participatory system) modeled on\b/i.test(concept?.form || '')) {
|
|
95
|
+
errors.push(`concept ${id} is a generic wrapper around another artifact`);
|
|
96
|
+
}
|
|
97
|
+
if (/\b(?:in the style of|styled like|copy of)\b/i.test(concept?.form || '')) {
|
|
98
|
+
errors.push(`concept ${id} contains imitation language`);
|
|
99
|
+
}
|
|
100
|
+
if (BLAND_FORM_RE.test(concept?.form || '')) {
|
|
101
|
+
errors.push(`concept ${id} is framed as a literal software or operations archetype instead of an inspiring visual world`);
|
|
102
|
+
}
|
|
103
|
+
return errors;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Fingerprint of everything a reviewer judged. Reviews carry this hash so an
|
|
107
|
+
// approval cannot silently survive a content edit: the validator rejects any
|
|
108
|
+
// review whose hash no longer matches the concept it points at.
|
|
109
|
+
export function conceptContentHash(concept) {
|
|
110
|
+
const payload = [
|
|
111
|
+
concept?.form ?? '',
|
|
112
|
+
concept?.lineage ?? '',
|
|
113
|
+
JSON.stringify(concept?.tags ?? []),
|
|
114
|
+
JSON.stringify(concept?.system ?? []),
|
|
115
|
+
concept?.spark ?? '',
|
|
116
|
+
concept?.webLeverage ?? '',
|
|
117
|
+
].join('\n');
|
|
118
|
+
return crypto.createHash('sha256').update(payload).digest('hex').slice(0, 12);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function readConceptCatalog(catalogPath, reviewsPath) {
|
|
122
|
+
const catalog = JSON.parse(readFileSync(catalogPath, 'utf8'));
|
|
123
|
+
const reviewData = JSON.parse(readFileSync(reviewsPath, 'utf8'));
|
|
124
|
+
const reviews = reviewData.reviews || {};
|
|
125
|
+
const wellsById = new Map((catalog.wells || []).map(well => [well.id, well]));
|
|
126
|
+
const concepts = [];
|
|
127
|
+
|
|
128
|
+
for (const family of catalog.families || []) {
|
|
129
|
+
for (const concept of family.concepts || []) {
|
|
130
|
+
concepts.push({
|
|
131
|
+
...concept,
|
|
132
|
+
familyId: family.id,
|
|
133
|
+
familyLabel: family.label,
|
|
134
|
+
wellId: family.well || null,
|
|
135
|
+
wellLabel: wellsById.get(family.well)?.label || null,
|
|
136
|
+
wellTier: wellsById.get(family.well)?.tier || null,
|
|
137
|
+
status: reviews[concept.id]?.status || 'pending',
|
|
138
|
+
review: reviews[concept.id] || null,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return { catalog, reviewData, reviews, concepts };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function validateConceptCatalog(catalog, reviewData, {
|
|
147
|
+
expectedTotal,
|
|
148
|
+
minimumTotal,
|
|
149
|
+
requireApprovedMinimum = true,
|
|
150
|
+
} = {}) {
|
|
151
|
+
const errors = [];
|
|
152
|
+
const warnings = [];
|
|
153
|
+
const familyIds = new Set();
|
|
154
|
+
const conceptIds = new Set();
|
|
155
|
+
const normalizedForms = new Map();
|
|
156
|
+
const concepts = [];
|
|
157
|
+
|
|
158
|
+
if (!Number.isInteger(catalog?.schemaVersion) || catalog.schemaVersion < 7) {
|
|
159
|
+
errors.push('catalog.schemaVersion must be 7 or newer');
|
|
160
|
+
}
|
|
161
|
+
if (typeof catalog?.catalogVersion !== 'string' || !catalog.catalogVersion.trim()) {
|
|
162
|
+
errors.push('catalog.catalogVersion must be a non-empty string');
|
|
163
|
+
}
|
|
164
|
+
if (typeof catalog?.qualityBar?.principle !== 'string' || catalog.qualityBar.principle.trim().length < 80) {
|
|
165
|
+
errors.push('catalog.qualityBar.principle must define the universal creative bar');
|
|
166
|
+
}
|
|
167
|
+
if (!Array.isArray(catalog?.qualityBar?.rejectIf) || catalog.qualityBar.rejectIf.length < 5) {
|
|
168
|
+
errors.push('catalog.qualityBar.rejectIf must define at least five rejection gates');
|
|
169
|
+
}
|
|
170
|
+
if (!Array.isArray(catalog?.qualityBar?.reviewAxes) || catalog.qualityBar.reviewAxes.length < 8) {
|
|
171
|
+
errors.push('catalog.qualityBar.reviewAxes must define at least eight review axes');
|
|
172
|
+
}
|
|
173
|
+
if (!Array.isArray(catalog?.families) || catalog.families.length < 3) {
|
|
174
|
+
errors.push('catalog.families must contain at least three families');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const wellIds = new Set();
|
|
178
|
+
if (!Array.isArray(catalog?.wells) || catalog.wells.length < 5) {
|
|
179
|
+
errors.push('catalog.wells must define at least five inspiration wells');
|
|
180
|
+
}
|
|
181
|
+
for (const well of catalog?.wells || []) {
|
|
182
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(well.id || '')) {
|
|
183
|
+
errors.push(`invalid well id: ${String(well.id)}`);
|
|
184
|
+
} else if (wellIds.has(well.id)) {
|
|
185
|
+
errors.push(`duplicate well id: ${well.id}`);
|
|
186
|
+
}
|
|
187
|
+
wellIds.add(well.id);
|
|
188
|
+
if (typeof well.label !== 'string' || !well.label.trim()) {
|
|
189
|
+
errors.push(`well ${well.id || '(unknown)'} needs a label`);
|
|
190
|
+
}
|
|
191
|
+
if (typeof well.description !== 'string' || well.description.trim().length < 40) {
|
|
192
|
+
errors.push(`well ${well.id || '(unknown)'} needs a description of at least 40 characters`);
|
|
193
|
+
}
|
|
194
|
+
if (!WELL_TIERS.includes(well.tier)) {
|
|
195
|
+
errors.push(`well ${well.id || '(unknown)'} needs a tier of ${WELL_TIERS.join(', ')}, got: ${String(well.tier)}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const tiersPresent = new Set((catalog?.wells || []).map(well => well.tier).filter(tier => WELL_TIERS.includes(tier)));
|
|
199
|
+
for (const tier of WELL_TIERS) {
|
|
200
|
+
if ((catalog?.wells || []).length > 0 && !tiersPresent.has(tier)) {
|
|
201
|
+
errors.push(`no well declares the ${tier} tier`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const populatedWells = new Set();
|
|
205
|
+
|
|
206
|
+
for (const family of catalog?.families || []) {
|
|
207
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(family.id || '')) {
|
|
208
|
+
errors.push(`invalid family id: ${String(family.id)}`);
|
|
209
|
+
} else if (familyIds.has(family.id)) {
|
|
210
|
+
errors.push(`duplicate family id: ${family.id}`);
|
|
211
|
+
}
|
|
212
|
+
familyIds.add(family.id);
|
|
213
|
+
if (typeof family.label !== 'string' || !family.label.trim()) {
|
|
214
|
+
errors.push(`family ${family.id || '(unknown)'} needs a label`);
|
|
215
|
+
}
|
|
216
|
+
if (!wellIds.has(family.well)) {
|
|
217
|
+
errors.push(`family ${family.id || '(unknown)'} must belong to a declared well, got: ${String(family.well)}`);
|
|
218
|
+
} else {
|
|
219
|
+
populatedWells.add(family.well);
|
|
220
|
+
}
|
|
221
|
+
if (!Array.isArray(family.concepts) || family.concepts.length === 0) {
|
|
222
|
+
errors.push(`family ${family.id || '(unknown)'} has no concepts`);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
for (const concept of family.concepts) {
|
|
227
|
+
concepts.push(concept);
|
|
228
|
+
if (conceptIds.has(concept.id)) {
|
|
229
|
+
errors.push(`duplicate concept id: ${concept.id}`);
|
|
230
|
+
}
|
|
231
|
+
errors.push(...validateConceptEntry(concept, { existingForms: normalizedForms }));
|
|
232
|
+
conceptIds.add(concept.id);
|
|
233
|
+
const normalized = normalizeConceptForm(concept.form);
|
|
234
|
+
if (normalized) normalizedForms.set(normalized, concept.id);
|
|
235
|
+
if (typeof concept.webLeverage === 'string' && !WEB_LEVERAGE_RE.test(concept.webLeverage)) {
|
|
236
|
+
warnings.push(`concept ${concept.id} web leverage should be checked for a specific browser-native capability`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
for (const well of catalog?.wells || []) {
|
|
242
|
+
if (well.id && !populatedWells.has(well.id)) {
|
|
243
|
+
errors.push(`well ${well.id} has no families`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (expectedTotal !== undefined && concepts.length !== expectedTotal) {
|
|
248
|
+
errors.push(`expected ${expectedTotal} concepts, found ${concepts.length}`);
|
|
249
|
+
}
|
|
250
|
+
if (minimumTotal !== undefined && concepts.length < minimumTotal) {
|
|
251
|
+
errors.push(`expected at least ${minimumTotal} concepts, found ${concepts.length}`);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (!Number.isInteger(reviewData?.schemaVersion) || reviewData.schemaVersion < 2) {
|
|
255
|
+
errors.push('reviews.schemaVersion must be 2 or newer');
|
|
256
|
+
}
|
|
257
|
+
const conceptsById = new Map(concepts.map(concept => [concept.id, concept]));
|
|
258
|
+
for (const [id, review] of Object.entries(reviewData?.reviews || {})) {
|
|
259
|
+
if (!conceptIds.has(id)) errors.push(`review references missing concept: ${id}`);
|
|
260
|
+
if (!CONCEPT_STATUSES.has(review?.status)) errors.push(`invalid review status for ${id}: ${String(review?.status)}`);
|
|
261
|
+
if (typeof review?.reviewedBy !== 'string' || !review.reviewedBy.trim()) {
|
|
262
|
+
errors.push(`review ${id} needs reviewedBy`);
|
|
263
|
+
}
|
|
264
|
+
if (typeof review?.reviewedAt !== 'string' || Number.isNaN(Date.parse(review.reviewedAt))) {
|
|
265
|
+
errors.push(`review ${id} needs an ISO reviewedAt timestamp`);
|
|
266
|
+
}
|
|
267
|
+
if (typeof review?.formHash !== 'string' || !review.formHash.trim()) {
|
|
268
|
+
errors.push(`review ${id} needs a formHash of the reviewed content`);
|
|
269
|
+
} else if (conceptsById.has(id) && review.formHash !== conceptContentHash(conceptsById.get(id))) {
|
|
270
|
+
errors.push(`review ${id} is stale: concept content changed since it was reviewed; reset or re-review it`);
|
|
271
|
+
}
|
|
272
|
+
if (review?.note !== undefined && (typeof review.note !== 'string' || !review.note.trim() || review.note.length > 500)) {
|
|
273
|
+
errors.push(`review ${id} note must be a non-empty string of 500 characters or fewer`);
|
|
274
|
+
}
|
|
275
|
+
// Rating grades how strong an approved concept is (3 exceptional, 2 solid,
|
|
276
|
+
// 1 marginal keep). Optional, approved-only, and read as a calibration
|
|
277
|
+
// signal for future authoring rounds.
|
|
278
|
+
if (review?.rating !== undefined) {
|
|
279
|
+
if (![1, 2, 3].includes(review.rating)) {
|
|
280
|
+
errors.push(`review ${id} rating must be 1, 2, or 3`);
|
|
281
|
+
} else if (review.status !== 'approved') {
|
|
282
|
+
errors.push(`review ${id} rating only applies to approved concepts`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const wellTierById = new Map((catalog?.wells || []).map(well => [well.id, well.tier]));
|
|
288
|
+
const approved = concepts.filter(concept => reviewData?.reviews?.[concept.id]?.status === 'approved');
|
|
289
|
+
const approvedTiers = new Set(
|
|
290
|
+
(catalog?.families || [])
|
|
291
|
+
.filter(family => family.concepts?.some(concept => reviewData?.reviews?.[concept.id]?.status === 'approved'))
|
|
292
|
+
.map(family => wellTierById.get(family.well))
|
|
293
|
+
.filter(tier => WELL_TIERS.includes(tier))
|
|
294
|
+
);
|
|
295
|
+
if (requireApprovedMinimum && approved.length < 3) errors.push('at least three concepts must be approved');
|
|
296
|
+
if (requireApprovedMinimum && approvedTiers.size < WELL_TIERS.length) {
|
|
297
|
+
errors.push('approved concepts must cover every challenger tier');
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return {
|
|
301
|
+
errors,
|
|
302
|
+
warnings,
|
|
303
|
+
stats: {
|
|
304
|
+
wells: wellIds.size,
|
|
305
|
+
families: familyIds.size,
|
|
306
|
+
concepts: concepts.length,
|
|
307
|
+
approved: approved.length,
|
|
308
|
+
pending: concepts.length - Object.keys(reviewData?.reviews || {}).length,
|
|
309
|
+
rejected: Object.values(reviewData?.reviews || {}).filter(review => review?.status === 'rejected').length,
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export function approvedPoolRevision(concepts) {
|
|
315
|
+
const payload = concepts
|
|
316
|
+
.filter(concept => concept.status === 'approved')
|
|
317
|
+
.map(concept => `${concept.familyId}:${concept.id}:${concept.strength}:${concept.form}:${concept.spark}:${JSON.stringify(concept.system)}:${concept.webLeverage}`)
|
|
318
|
+
.sort()
|
|
319
|
+
.join('\n');
|
|
320
|
+
return crypto.createHash('sha256').update(payload).digest('hex').slice(0, 12);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export function deterministicRank(items, input, idFor = item => item.id) {
|
|
324
|
+
return [...items].sort((a, b) => {
|
|
325
|
+
const scoreA = crypto.createHash('sha256').update(`${input}:${idFor(a)}`).digest('hex');
|
|
326
|
+
const scoreB = crypto.createHash('sha256').update(`${input}:${idFor(b)}`).digest('hex');
|
|
327
|
+
return scoreB.localeCompare(scoreA) || idFor(a).localeCompare(idFor(b));
|
|
328
|
+
});
|
|
329
|
+
}
|