@xopcai/xopc 0.0.142 → 0.0.143
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 +1 -1
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/activity-center-store-jITiX2vJ.js +1 -0
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BawPxiu5.js → agent-avatar-dicebear-DiME9u_P.js} +1 -1
- package/dist/gateway/static/root/assets/agents-DzBXhZXO.js +2 -0
- package/dist/gateway/static/root/assets/{app-management-settings-panel-81xd1p9R.js → app-management-settings-panel-Cuo7SbUP.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-DYeQsYU8.js → appearance-settings-DUfdNQqk.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-CKuKK5AU.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-D_oa7oti.js → archive-plugin-B-Qk6cGr.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-Cd-bwI2N.js → attachment-load-Di6EEbQX.js} +1 -1
- package/dist/gateway/static/root/assets/automation-suggestion-card-DGxvRxtO.js +1 -0
- package/dist/gateway/static/root/assets/automations-page-D-FF_WKV.js +4 -0
- package/dist/gateway/static/root/assets/{binary-plugins-O8svLKWw.js → binary-plugins-ZaOZDH2I.js} +1 -1
- package/dist/gateway/static/root/assets/block-editor-BTFhjWfg.js +184 -0
- package/dist/gateway/static/root/assets/browser-settings-page-BvKLdEQt.js +8 -0
- package/dist/gateway/static/root/assets/{capability-presets-api-dJy1Eqgx.js → capability-presets-api-BU-pVZiZ.js} +1 -1
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-DgyeEwzh.js +2 -0
- package/dist/gateway/static/root/assets/{channel-recipient-api-Bfuhp2ty.js → channel-recipient-api-DuulnhIj.js} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-BbVsdD_I.js +1 -0
- package/dist/gateway/static/root/assets/channels-status-swr-B5lVrUsN.js +1 -0
- package/dist/gateway/static/root/assets/check-BODqo66o.js +1 -0
- package/dist/gateway/static/root/assets/chunk-QUQL4437-DXsxWP7r.js +4 -0
- package/dist/gateway/static/root/assets/circle-alert-RzVebuX2.js +1 -0
- package/dist/gateway/static/root/assets/connectors-page-B8QqVy3I.js +2 -0
- package/dist/gateway/static/root/assets/{desktop-pet-DFMfIb5F.js → desktop-pet---yzVxVR.js} +1 -1
- package/dist/gateway/static/root/assets/desktop-pet-settings-Dc3gqBJE.js +1 -0
- package/dist/gateway/static/root/assets/{directory-picker-path-field-BrYt1gAr.js → directory-picker-path-field-DCmOGLtK.js} +1 -1
- package/dist/gateway/static/root/assets/dreaming-settings-BgT5KZVe.js +3 -0
- package/dist/gateway/static/root/assets/{extension-debug-page-Bh630pLD.js → extension-debug-page-ByaKTTq4.js} +1 -1
- package/dist/gateway/static/root/assets/extension-page-BmRzHAZr.js +1 -0
- package/dist/gateway/static/root/assets/extension-settings-page-JUtwIhbF.js +1 -0
- package/dist/gateway/static/root/assets/{fetch-B1WtuprY.js → fetch-8QNN25Sh.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-api-De2N821l.js → gateway-config-api-CxicF50_.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-settings-Bz2I_EO5.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-startup-retry-nEujFSDj.js → gateway-startup-retry-5YBnS9Fj.js} +1 -1
- package/dist/gateway/static/root/assets/goal-create-dialog-VcoyuZGN.js +1 -0
- package/dist/gateway/static/root/assets/goal-detail-page-Cilkap2G.js +4 -0
- package/dist/gateway/static/root/assets/{goals-config-api-DUy3eEse.js → goals-config-api-CwcHRdC0.js} +1 -1
- package/dist/gateway/static/root/assets/goals-page-C6eoni4z.js +2 -0
- package/dist/gateway/static/root/assets/goals-settings-o4i-qAOS.js +1 -0
- package/dist/gateway/static/root/assets/heartbeat-settings-DQQkETX8.js +1 -0
- package/dist/gateway/static/root/assets/index-BKRqeRHm.js +257 -0
- package/dist/gateway/static/root/assets/index-CphxClbs.css +1 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-CVIwwM15.js → keyboard-shortcuts-settings-LT6qB-ua.js} +1 -1
- package/dist/gateway/static/root/assets/logs-page-Dli2e3fS.js +7 -0
- package/dist/gateway/static/root/assets/{markdown-split-B_6us9j7.js → markdown-split-Dw-yE2-y.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-D_fryIyj.js → media-plugins-D9NNNUgE.js} +1 -1
- package/dist/gateway/static/root/assets/messages-CzKxM6I4.js +5 -0
- package/dist/gateway/static/root/assets/models-hub-panel-DVn2Q1Ik.js +2 -0
- package/dist/gateway/static/root/assets/notes-page-CRgbJGgk.js +1 -0
- package/dist/gateway/static/root/assets/notes-workbench-BxZRHLWx.js +2 -0
- package/dist/gateway/static/root/assets/{page-tabs-D_8jGlqx.js → page-tabs-D4hkWVt_.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-BBLMK8Mp.js → preview-open-alternatives-CIckv0uy.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-Doz53xLn.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-DoMtcRLg.js +1 -0
- package/dist/gateway/static/root/assets/remote-access-hub-BeHVEgrm.js +1 -0
- package/dist/gateway/static/root/assets/{save-bar-controls-DVS3FR5r.js → save-bar-controls-B0b42kB2.js} +1 -1
- package/dist/gateway/static/root/assets/{schedule-field-D6vKd6-T.js → schedule-field-BtjEkczK.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-BPy4lbIh.js → schema-form-Bf0bk3i6.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-Bk4bQsBe.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-DdFyaRMm.js +1 -0
- package/dist/gateway/static/root/assets/{settings-collapsible-section-WzdikxPt.js → settings-collapsible-section-BTKTdTNX.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-form-section-CvfzhBV-.js → settings-form-section-DL4P0sAj.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-BxR-Ulhi.js → settings-loading-skeleton-BV6KFNj4.js} +1 -1
- package/dist/gateway/static/root/assets/settings-page-B_4DsX5W.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-layout-CKefvbYi.js → settings-page-layout-CyGlrInB.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-DJ1_MLgX.js +1 -0
- package/dist/gateway/static/root/assets/share-preview-page-BQBV7YrV.js +2 -0
- package/dist/gateway/static/root/assets/shares-settings-0VuFLBeU.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-DO87Ckeo.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-D3VdtxAn.js +2 -0
- package/dist/gateway/static/root/assets/{system-settings-panel-BokgAgf7.js → system-settings-panel-D85fBBuI.js} +1 -1
- package/dist/gateway/static/root/assets/{typed-models-lib-BwHlNL3L.js → typed-models-lib-CwEuYrHX.js} +1 -1
- package/dist/gateway/static/root/assets/{use-channel-catalog-DR11ap3A.js → use-channel-catalog-COXIfXcl.js} +1 -1
- package/dist/gateway/static/root/assets/user-context-page-m9JVQ73F.js +1 -0
- package/dist/gateway/static/root/assets/user-profile-fields-editor-DtQiuY7E.js +1 -0
- package/dist/gateway/static/root/assets/user-profile-settings-panel-CWM0fEpb.js +1 -0
- package/dist/gateway/static/root/assets/{utils-BKUWB-TT.js → utils--BO6xT3u.js} +1 -1
- package/dist/gateway/static/root/assets/voice-api-key-field-LoT3wgZ9.js +1 -0
- package/dist/gateway/static/root/assets/with-selector-aYPsXwdl.js +1 -0
- package/dist/gateway/static/root/assets/work-item-detail-page-DSTMz_mO.js +1 -0
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-CL_rnAUB.js → workflow-run-setup-panel-B35lJzvm.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-BfSm9oR8.js +11 -0
- package/dist/gateway/static/root/assets/workflows-page-DLioOiRN.css +1 -0
- package/dist/gateway/static/root/connector-icons/README.md +11 -0
- package/dist/gateway/static/root/connector-icons/airtable.svg +13 -0
- package/dist/gateway/static/root/connector-icons/asana.svg +15 -0
- package/dist/gateway/static/root/connector-icons/brave-search.svg +1 -0
- package/dist/gateway/static/root/connector-icons/clickup.svg +19 -0
- package/dist/gateway/static/root/connector-icons/composio.svg +266 -0
- package/dist/gateway/static/root/connector-icons/discord.svg +15 -0
- package/dist/gateway/static/root/connector-icons/dropbox.svg +152 -0
- package/dist/gateway/static/root/connector-icons/excel.svg +56 -0
- package/dist/gateway/static/root/connector-icons/fetch.svg +6 -0
- package/dist/gateway/static/root/connector-icons/figma.svg +178 -0
- package/dist/gateway/static/root/connector-icons/filesystem.svg +6 -0
- package/dist/gateway/static/root/connector-icons/github.svg +10 -0
- package/dist/gateway/static/root/connector-icons/gmail.svg +3 -0
- package/dist/gateway/static/root/connector-icons/google-calendar.svg +3 -0
- package/dist/gateway/static/root/connector-icons/google-docs.svg +25 -0
- package/dist/gateway/static/root/connector-icons/google-drive.svg +25 -0
- package/dist/gateway/static/root/connector-icons/google-sheets.svg +1 -0
- package/dist/gateway/static/root/connector-icons/hubspot.svg +142 -0
- package/dist/gateway/static/root/connector-icons/jira.svg +15 -0
- package/dist/gateway/static/root/connector-icons/linear.svg +5 -0
- package/dist/gateway/static/root/connector-icons/memory.svg +5 -0
- package/dist/gateway/static/root/connector-icons/microsoft-teams.svg +33 -0
- package/dist/gateway/static/root/connector-icons/notion.svg +5 -0
- package/dist/gateway/static/root/connector-icons/one-drive.svg +13 -0
- package/dist/gateway/static/root/connector-icons/outlook.svg +76 -0
- package/dist/gateway/static/root/connector-icons/playwright.svg +9 -0
- package/dist/gateway/static/root/connector-icons/salesforce.svg +17 -0
- package/dist/gateway/static/root/connector-icons/sequential-thinking.svg +8 -0
- package/dist/gateway/static/root/connector-icons/shopify.svg +5 -0
- package/dist/gateway/static/root/connector-icons/slack.svg +9 -0
- package/dist/gateway/static/root/connector-icons/spotify.svg +43 -0
- package/dist/gateway/static/root/connector-icons/stripe.svg +11 -0
- package/dist/gateway/static/root/connector-icons/telegram.svg +130 -0
- package/dist/gateway/static/root/connector-icons/time.svg +6 -0
- package/dist/gateway/static/root/connector-icons/todoist.svg +277 -0
- package/dist/gateway/static/root/connector-icons/trello.svg +19 -0
- package/dist/gateway/static/root/connector-icons/twitter.svg +128 -0
- package/dist/gateway/static/root/connector-icons/whatsapp.svg +61 -0
- package/dist/gateway/static/root/connector-icons/youtube.svg +11 -0
- package/dist/gateway/static/root/index.html +9 -6
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-manager.d.ts +2 -0
- package/dist/src/agent/agent-manager.js +8 -0
- package/dist/src/agent/agent-manager.js.map +1 -1
- package/dist/src/agent/background-review/prompts.d.ts +1 -1
- package/dist/src/agent/background-review/prompts.js +3 -2
- package/dist/src/agent/background-review/prompts.js.map +1 -1
- package/dist/src/agent/embedded/session-tool-result-guard.js +1 -1
- package/dist/src/agent/embedded/xopc-tools-bridge.d.ts +9 -0
- package/dist/src/agent/embedded/xopc-tools-bridge.js +71 -3
- package/dist/src/agent/embedded/xopc-tools-bridge.js.map +1 -1
- package/dist/src/agent/goals/post-turn.js +5 -4
- package/dist/src/agent/goals/post-turn.js.map +1 -1
- package/dist/src/agent/mcp/mcp-transport.js +4 -1
- package/dist/src/agent/mcp/mcp-transport.js.map +1 -1
- package/dist/src/agent/memory/context/planner.d.ts +1 -0
- package/dist/src/agent/memory/context/planner.js +60 -14
- package/dist/src/agent/memory/context/planner.js.map +1 -1
- package/dist/src/agent/memory/context/types.d.ts +3 -1
- package/dist/src/agent/memory/lifecycle.d.ts +11 -0
- package/dist/src/agent/memory/lifecycle.js +50 -0
- package/dist/src/agent/memory/lifecycle.js.map +1 -0
- package/dist/src/agent/memory/source-origin.d.ts +3 -0
- package/dist/src/agent/memory/source-origin.js +19 -0
- package/dist/src/agent/memory/source-origin.js.map +1 -0
- package/dist/src/agent/memory/understanding/service.js +5 -0
- package/dist/src/agent/memory/understanding/service.js.map +1 -1
- package/dist/src/agent/memory/user-context-coordinator.js +7 -2
- package/dist/src/agent/memory/user-context-coordinator.js.map +1 -1
- package/dist/src/agent/prompt/sections/behavior.d.ts +2 -0
- package/dist/src/agent/prompt/sections/behavior.js +30 -1
- package/dist/src/agent/prompt/sections/behavior.js.map +1 -1
- package/dist/src/agent/prompt/sections/tooling.js +1 -1
- package/dist/src/agent/prompt/sections/tooling.js.map +1 -1
- package/dist/src/agent/prompt/service-prompt-builder.js +8 -1
- package/dist/src/agent/prompt/service-prompt-builder.js.map +1 -1
- package/dist/src/agent/prompt/system-prompt.d.ts +2 -0
- package/dist/src/agent/prompt/system-prompt.js +6 -3
- package/dist/src/agent/prompt/system-prompt.js.map +1 -1
- package/dist/src/agent/service/process-direct-streaming.js +22 -0
- package/dist/src/agent/service/process-direct-streaming.js.map +1 -1
- package/dist/src/agent/service.d.ts +2 -0
- package/dist/src/agent/service.js +9 -3
- package/dist/src/agent/service.js.map +1 -1
- package/dist/src/agent/starter-agents.js +1 -1
- package/dist/src/agent/starter-agents.js.map +1 -1
- package/dist/src/agent/tool-manuals/xopc-use.d.ts +1 -1
- package/dist/src/agent/tool-manuals/xopc-use.js +1 -1
- package/dist/src/agent/tool-manuals/xopc-use.js.map +1 -1
- package/dist/src/agent/tools/composio-tool.d.ts +18 -5
- package/dist/src/agent/tools/composio-tool.js +252 -35
- package/dist/src/agent/tools/composio-tool.js.map +1 -1
- package/dist/src/agent/tools/factory.js +7 -3
- package/dist/src/agent/tools/factory.js.map +1 -1
- package/dist/src/agent/tools/index.d.ts +1 -1
- package/dist/src/agent/tools/index.js +2 -2
- package/dist/src/agent/tools/workflow-tool.d.ts +0 -1
- package/dist/src/agent/tools/workflow-tool.js +3 -16
- package/dist/src/agent/tools/workflow-tool.js.map +1 -1
- package/dist/src/agent/workflow/builtins/index.d.ts +2 -28
- package/dist/src/agent/workflow/builtins/index.js +226 -41
- package/dist/src/agent/workflow/builtins/index.js.map +1 -1
- package/dist/src/agent/workflow/catalog.d.ts +32 -34
- package/dist/src/agent/workflow/catalog.js +158 -154
- package/dist/src/agent/workflow/catalog.js.map +1 -1
- package/dist/src/agent/workflow/index.d.ts +4 -6
- package/dist/src/agent/workflow/index.js +2 -5
- package/dist/src/agent/workflow/snapshot.d.ts +2 -2
- package/dist/src/agent/workflow/snapshot.js +2 -2
- package/dist/src/agent/workflow/snapshot.js.map +1 -1
- package/dist/src/agent/workflow/structured-output-tool.d.ts +2 -2
- package/dist/src/agent/workflow/structured-output-tool.js +2 -2
- package/dist/src/agent/workflow/structured-output-tool.js.map +1 -1
- package/dist/src/agent/workflow/subagent-runner.js +1 -1
- package/dist/src/agent/workflow/types.d.ts +31 -26
- package/dist/src/agent-manifest/index.d.ts +1 -0
- package/dist/src/agent-manifest/index.js +3 -1
- package/dist/src/agent-manifest/index.js.map +1 -1
- package/dist/src/agent-manifest/preset-chain.d.ts +10 -0
- package/dist/src/agent-manifest/preset-chain.js +32 -0
- package/dist/src/agent-manifest/preset-chain.js.map +1 -0
- package/dist/src/agent-manifest/resolver.js +3 -10
- package/dist/src/agent-manifest/resolver.js.map +1 -1
- package/dist/src/agent-manifest/schema.d.ts +4 -4
- package/dist/src/automations/api/routes.js +13 -1
- package/dist/src/automations/api/routes.js.map +1 -1
- package/dist/src/automations/domain/validation.d.ts +14 -14
- package/dist/src/automations/draft/automation-draft-validator.d.ts +3 -3
- package/dist/src/browser/providers/browser-ext-install.d.ts +11 -1
- package/dist/src/browser/providers/browser-ext-install.js +39 -14
- package/dist/src/browser/providers/browser-ext-install.js.map +1 -1
- package/dist/src/capabilities/store-connector.d.ts +0 -1
- package/dist/src/capabilities/store-connector.js +3 -5
- package/dist/src/capabilities/store-connector.js.map +1 -1
- package/dist/src/chat-commands/builtins/review.js +72 -73
- package/dist/src/chat-commands/builtins/review.js.map +1 -1
- package/dist/src/chat-commands/builtins/workflow.js +9 -54
- package/dist/src/chat-commands/builtins/workflow.js.map +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/extension-create.js +2 -2
- package/dist/src/cli/commands/extension-create.js.map +1 -1
- package/dist/src/cli/commands/extension-marketplace.js +42 -36
- package/dist/src/cli/commands/extension-marketplace.js.map +1 -1
- package/dist/src/cli/commands/extension-pack.d.ts +6 -0
- package/dist/src/cli/commands/extension-pack.js +3 -2
- package/dist/src/cli/commands/extension-pack.js.map +1 -1
- package/dist/src/commands/agents.config.d.ts +1 -0
- package/dist/src/commands/agents.config.js +1 -0
- package/dist/src/commands/agents.config.js.map +1 -1
- package/dist/src/config/schema.d.ts +6 -6
- package/dist/src/config/schema.js +6 -22
- package/dist/src/config/schema.js.map +1 -1
- package/dist/src/config/web-patch.d.ts +1 -1
- package/dist/src/connectors/approval.d.ts +2 -0
- package/dist/src/connectors/approval.js +33 -0
- package/dist/src/connectors/approval.js.map +1 -0
- package/dist/src/connectors/auth-provider-registry.d.ts +9 -0
- package/dist/src/connectors/auth-provider-registry.js +17 -0
- package/dist/src/connectors/auth-provider-registry.js.map +1 -0
- package/dist/src/connectors/builtin-catalog.js +55 -116
- package/dist/src/connectors/builtin-catalog.js.map +1 -1
- package/dist/src/connectors/catalog.js +7 -2
- package/dist/src/connectors/catalog.js.map +1 -1
- package/dist/src/connectors/composio-catalog.d.ts +19 -0
- package/dist/src/connectors/composio-catalog.js +237 -0
- package/dist/src/connectors/composio-catalog.js.map +1 -0
- package/dist/src/connectors/composio-logo.d.ts +1 -0
- package/dist/src/connectors/composio-logo.js +51 -0
- package/dist/src/connectors/composio-logo.js.map +1 -0
- package/dist/src/connectors/composio-sessions.d.ts +116 -0
- package/dist/src/connectors/composio-sessions.js +296 -0
- package/dist/src/connectors/composio-sessions.js.map +1 -0
- package/dist/src/connectors/composio-triggers.d.ts +17 -0
- package/dist/src/connectors/composio-triggers.js +48 -5
- package/dist/src/connectors/composio-triggers.js.map +1 -1
- package/dist/src/connectors/composio.d.ts +31 -2
- package/dist/src/connectors/composio.js +374 -151
- package/dist/src/connectors/composio.js.map +1 -1
- package/dist/src/connectors/connector-memory-sync.d.ts +15 -0
- package/dist/src/connectors/connector-memory-sync.js +90 -0
- package/dist/src/connectors/connector-memory-sync.js.map +1 -0
- package/dist/src/connectors/install.js +35 -92
- package/dist/src/connectors/install.js.map +1 -1
- package/dist/src/connectors/instances.js +6 -2
- package/dist/src/connectors/instances.js.map +1 -1
- package/dist/src/connectors/integration-strategy.d.ts +3 -0
- package/dist/src/connectors/integration-strategy.js +29 -0
- package/dist/src/connectors/integration-strategy.js.map +1 -0
- package/dist/src/connectors/policy.d.ts +13 -0
- package/dist/src/connectors/policy.js +48 -0
- package/dist/src/connectors/policy.js.map +1 -0
- package/dist/src/connectors/providers.js +1 -1
- package/dist/src/connectors/runtime-adapter-registry.d.ts +25 -0
- package/dist/src/connectors/runtime-adapter-registry.js +154 -0
- package/dist/src/connectors/runtime-adapter-registry.js.map +1 -0
- package/dist/src/connectors/types.d.ts +113 -4
- package/dist/src/connectors/workflow-preflight.d.ts +20 -0
- package/dist/src/connectors/workflow-preflight.js +70 -0
- package/dist/src/connectors/workflow-preflight.js.map +1 -0
- package/dist/src/extensions/install-transaction.d.ts +16 -0
- package/dist/src/extensions/install-transaction.js +76 -0
- package/dist/src/extensions/install-transaction.js.map +1 -0
- package/dist/src/extensions/install.d.ts +2 -0
- package/dist/src/extensions/install.js +23 -1
- package/dist/src/extensions/install.js.map +1 -1
- package/dist/src/gateway/agents-admin.d.ts +2 -0
- package/dist/src/gateway/agents-admin.js +7 -0
- package/dist/src/gateway/agents-admin.js.map +1 -1
- package/dist/src/gateway/capability-presets-admin.d.ts +11 -0
- package/dist/src/gateway/capability-presets-admin.js +11 -4
- package/dist/src/gateway/capability-presets-admin.js.map +1 -1
- package/dist/src/gateway/chat-stream/mapper.js +17 -0
- package/dist/src/gateway/chat-stream/mapper.js.map +1 -1
- package/dist/src/gateway/chat-stream/protocol.d.ts +18 -1
- package/dist/src/gateway/hono/lib/config-payload.d.ts +3 -3
- package/dist/src/gateway/hono/routes/agents.js +3 -0
- package/dist/src/gateway/hono/routes/agents.js.map +1 -1
- package/dist/src/gateway/hono/routes/capability-presets.js +19 -1
- package/dist/src/gateway/hono/routes/capability-presets.js.map +1 -1
- package/dist/src/gateway/hono/routes/connectors.js +188 -25
- package/dist/src/gateway/hono/routes/connectors.js.map +1 -1
- package/dist/src/gateway/hono/routes/goals.js +22 -3
- package/dist/src/gateway/hono/routes/goals.js.map +1 -1
- package/dist/src/gateway/hono/routes/home.d.ts +60 -1
- package/dist/src/gateway/hono/routes/home.js +244 -18
- package/dist/src/gateway/hono/routes/home.js.map +1 -1
- package/dist/src/gateway/hono/routes/lazy-bundles.js +8 -0
- package/dist/src/gateway/hono/routes/lazy-bundles.js.map +1 -1
- package/dist/src/gateway/hono/routes/memory.js +14 -1
- package/dist/src/gateway/hono/routes/memory.js.map +1 -1
- package/dist/src/gateway/hono/routes/projects.js +103 -2
- package/dist/src/gateway/hono/routes/projects.js.map +1 -1
- package/dist/src/gateway/hono/routes/public-gateway.js +93 -0
- package/dist/src/gateway/hono/routes/public-gateway.js.map +1 -1
- package/dist/src/gateway/hono/routes/workflows.js +137 -22
- package/dist/src/gateway/hono/routes/workflows.js.map +1 -1
- package/dist/src/gateway/hono/routes/you.d.ts +23 -0
- package/dist/src/gateway/hono/routes/you.js +538 -0
- package/dist/src/gateway/hono/routes/you.js.map +1 -0
- package/dist/src/gateway/hono/sse.d.ts +2 -1
- package/dist/src/gateway/hono/sse.js +2 -1
- package/dist/src/gateway/hono/sse.js.map +1 -1
- package/dist/src/gateway/service/marketplace-service.d.ts +13 -1
- package/dist/src/gateway/service/marketplace-service.js +96 -40
- package/dist/src/gateway/service/marketplace-service.js.map +1 -1
- package/dist/src/gateway/service.d.ts +2 -0
- package/dist/src/gateway/service.js +7 -1
- package/dist/src/gateway/service.js.map +1 -1
- package/dist/src/goals/goal-service.d.ts +7 -5
- package/dist/src/goals/goal-service.js +25 -13
- package/dist/src/goals/goal-service.js.map +1 -1
- package/dist/src/goals/goal-store.js +46 -7
- package/dist/src/goals/goal-store.js.map +1 -1
- package/dist/src/goals/types.d.ts +24 -0
- package/dist/src/storage/sqlite/connector-repository.d.ts +49 -0
- package/dist/src/storage/sqlite/connector-repository.js +385 -0
- package/dist/src/storage/sqlite/connector-repository.js.map +1 -0
- package/dist/src/storage/sqlite/index.d.ts +3 -0
- package/dist/src/storage/sqlite/index.js +4 -1
- package/dist/src/storage/sqlite/migrations/030_connectors.sql +94 -0
- package/dist/src/storage/sqlite/migrations/031_connector_approvals.sql +24 -0
- package/dist/src/storage/sqlite/migrations/032_connector_webhook_deliveries.sql +15 -0
- package/dist/src/storage/sqlite/migrations/033_user_trust_policies.sql +6 -0
- package/dist/src/storage/sqlite/migrations/034_allow_global_auto_trust.sql +14 -0
- package/dist/src/storage/sqlite/migrations/035_user_profile_prompt_state.sql +7 -0
- package/dist/src/storage/sqlite/migrations/036_goal_outcome_metric.sql +12 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/migrations/runner.js.map +1 -1
- package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/user-profile-setup-repository.d.ts +3 -0
- package/dist/src/storage/sqlite/user-profile-setup-repository.js +34 -0
- package/dist/src/storage/sqlite/user-profile-setup-repository.js.map +1 -0
- package/dist/src/storage/sqlite/user-trust-repository.d.ts +3 -0
- package/dist/src/storage/sqlite/user-trust-repository.js +34 -0
- package/dist/src/storage/sqlite/user-trust-repository.js.map +1 -0
- package/dist/src/tui/components/assistant-message.js +15 -0
- package/dist/src/tui/components/assistant-message.js.map +1 -1
- package/dist/src/tui/tui-agent-events.js +85 -1
- package/dist/src/tui/tui-agent-events.js.map +1 -1
- package/dist/src/tui/tui-command-formatters.js +7 -7
- package/dist/src/tui/tui-command-formatters.js.map +1 -1
- package/dist/src/tui/tui-commands.js +1 -1
- package/dist/src/tui/tui-startup-resources.js +1 -1
- package/dist/src/user-context/import.d.ts +12 -0
- package/dist/src/user-context/import.js +48 -0
- package/dist/src/user-context/import.js.map +1 -0
- package/dist/src/user-context/profile.d.ts +37 -0
- package/dist/src/user-context/profile.js +165 -0
- package/dist/src/user-context/profile.js.map +1 -0
- package/dist/src/user-context/projection.d.ts +54 -0
- package/dist/src/user-context/projection.js +121 -0
- package/dist/src/user-context/projection.js.map +1 -0
- package/dist/src/user-context/source-recommendations.d.ts +13 -0
- package/dist/src/user-context/source-recommendations.js +86 -0
- package/dist/src/user-context/source-recommendations.js.map +1 -0
- package/dist/src/user-context/trust-policy.d.ts +11 -0
- package/dist/src/user-context/trust-policy.js +31 -0
- package/dist/src/user-context/trust-policy.js.map +1 -0
- package/dist/src/workflows/authoring/index.d.ts +1 -0
- package/dist/src/workflows/authoring/index.js +2 -0
- package/dist/src/workflows/authoring/workflow-draft-store.d.ts +33 -0
- package/dist/src/workflows/authoring/workflow-draft-store.js +74 -0
- package/dist/src/workflows/authoring/workflow-draft-store.js.map +1 -0
- package/dist/src/workflows/domain/definition-utils.d.ts +6 -4
- package/dist/src/workflows/domain/definition-utils.js +28 -26
- package/dist/src/workflows/domain/definition-utils.js.map +1 -1
- package/dist/src/workflows/domain/definition.d.ts +79 -6
- package/dist/src/workflows/domain/event.d.ts +18 -2
- package/dist/src/workflows/domain/index.js +3 -3
- package/dist/src/workflows/domain/run.d.ts +16 -2
- package/dist/src/workflows/domain/run.js.map +1 -1
- package/dist/src/workflows/domain/validation.d.ts +9 -5
- package/dist/src/workflows/domain/validation.js +183 -40
- package/dist/src/workflows/domain/validation.js.map +1 -1
- package/dist/src/workflows/draft/workflow-draft-prompt.d.ts +2 -3
- package/dist/src/workflows/draft/workflow-draft-prompt.js +31 -73
- package/dist/src/workflows/draft/workflow-draft-prompt.js.map +1 -1
- package/dist/src/workflows/draft/workflow-draft-service.js +4 -8
- package/dist/src/workflows/draft/workflow-draft-service.js.map +1 -1
- package/dist/src/workflows/draft/workflow-draft-validator.js +29 -37
- package/dist/src/workflows/draft/workflow-draft-validator.js.map +1 -1
- package/dist/src/workflows/draft/workflow-draft.types.d.ts +4 -4
- package/dist/src/workflows/engine/projector.js +43 -1
- package/dist/src/workflows/engine/projector.js.map +1 -1
- package/dist/src/workflows/engine/workflow-engine.d.ts +2 -3
- package/dist/src/workflows/engine/workflow-engine.js +24 -4
- package/dist/src/workflows/engine/workflow-engine.js.map +1 -1
- package/dist/src/workflows/index.js +4 -7
- package/dist/src/workflows/registry/catalog-workflow-definition-registry.js +1 -9
- package/dist/src/workflows/registry/catalog-workflow-definition-registry.js.map +1 -1
- package/dist/src/workflows/runtime/graph-workflow-runtime.d.ts +10 -0
- package/dist/src/workflows/runtime/graph-workflow-runtime.js +295 -0
- package/dist/src/workflows/runtime/graph-workflow-runtime.js.map +1 -0
- package/dist/src/workflows/runtime/index.d.ts +1 -2
- package/dist/src/workflows/runtime/index.js +2 -5
- package/dist/src/workflows/runtime/workflow-runtime-port.d.ts +5 -8
- package/dist/src/workflows/service/workflow-run-service.js +15 -1
- package/dist/src/workflows/service/workflow-run-service.js.map +1 -1
- package/dist/src/workflows/service/workflow-run-service.types.d.ts +2 -1
- package/package.json +4 -3
- package/dist/gateway/static/root/assets/agents-CyvCIHnB.js +0 -2
- package/dist/gateway/static/root/assets/apps-page-DK_Vx6nl.js +0 -1
- package/dist/gateway/static/root/assets/automation-suggestion-card-B1LV3YYv.js +0 -1
- package/dist/gateway/static/root/assets/automations-page-fzrovqhv.js +0 -4
- package/dist/gateway/static/root/assets/block-editor-Dhj5f4Bx.js +0 -184
- package/dist/gateway/static/root/assets/browser-settings-page-BDn-n-UB.js +0 -8
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-Co5ipo_Q.js +0 -1
- package/dist/gateway/static/root/assets/channels-settings-BWlpaxg9.js +0 -1
- package/dist/gateway/static/root/assets/channels-status-swr-D_jkIZLV.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-BcekbW4q.js +0 -2
- package/dist/gateway/static/root/assets/desktop-pet-settings-BJCUuL8Y.js +0 -1
- package/dist/gateway/static/root/assets/dreaming-settings-BN1Z2mIo.js +0 -3
- package/dist/gateway/static/root/assets/extension-page-B-1KxvVy.js +0 -1
- package/dist/gateway/static/root/assets/extension-settings-page-BF9NACI3.js +0 -1
- package/dist/gateway/static/root/assets/gateway-settings-DN9sNREz.js +0 -1
- package/dist/gateway/static/root/assets/goal-create-dialog-BpoQW8cD.js +0 -1
- package/dist/gateway/static/root/assets/goal-detail-page-CBRSPd0b.js +0 -4
- package/dist/gateway/static/root/assets/goals-page-BCcBi407.js +0 -2
- package/dist/gateway/static/root/assets/goals-settings-pkTXzXkh.js +0 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-ezsufgLQ.js +0 -1
- package/dist/gateway/static/root/assets/index-B8s8Pq5U.css +0 -1
- package/dist/gateway/static/root/assets/index-DcUaXYeb.js +0 -262
- package/dist/gateway/static/root/assets/logs-page-DQtTRXtj.js +0 -7
- package/dist/gateway/static/root/assets/messages-BXNELNBa.js +0 -3
- package/dist/gateway/static/root/assets/models-hub-panel-BP2M9n6Q.js +0 -2
- package/dist/gateway/static/root/assets/notes-page-CspveYaO.js +0 -1
- package/dist/gateway/static/root/assets/notes-workbench-BHwzJ0OC.js +0 -2
- package/dist/gateway/static/root/assets/project-detail-page-Dy3rsobs.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-CWKpPE0L.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-CqNRyXEo.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-MEME7ivF.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-JVd0qaSF.js +0 -1
- package/dist/gateway/static/root/assets/settings-page-DYEbB1EV.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-dWN8BJ3z.js +0 -1
- package/dist/gateway/static/root/assets/share-preview-page-D8foINzP.js +0 -2
- package/dist/gateway/static/root/assets/shares-settings-Tgbv1s7G.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-D_YK0b_Z.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-DGytfoZK.js +0 -2
- package/dist/gateway/static/root/assets/toast-z0toXu32.js +0 -1
- package/dist/gateway/static/root/assets/user-profile-settings-panel-8YtygcJp.js +0 -1
- package/dist/gateway/static/root/assets/voice-api-key-field-BVH71EFf.js +0 -1
- package/dist/gateway/static/root/assets/work-item-detail-page-JeTE7XNM.js +0 -1
- package/dist/gateway/static/root/assets/workflow-start-dialog-_u8Uc1ze.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-ixgk_y1l.js +0 -18
- package/dist/src/agent/workflow/builtins/audit-repo.d.ts +0 -13
- package/dist/src/agent/workflow/builtins/audit-repo.js +0 -183
- package/dist/src/agent/workflow/builtins/audit-repo.js.map +0 -1
- package/dist/src/agent/workflow/builtins/client-proposal.d.ts +0 -12
- package/dist/src/agent/workflow/builtins/client-proposal.js +0 -164
- package/dist/src/agent/workflow/builtins/client-proposal.js.map +0 -1
- package/dist/src/agent/workflow/builtins/competitor-scan.d.ts +0 -12
- package/dist/src/agent/workflow/builtins/competitor-scan.js +0 -164
- package/dist/src/agent/workflow/builtins/competitor-scan.js.map +0 -1
- package/dist/src/agent/workflow/builtins/content-draft.d.ts +0 -13
- package/dist/src/agent/workflow/builtins/content-draft.js +0 -159
- package/dist/src/agent/workflow/builtins/content-draft.js.map +0 -1
- package/dist/src/agent/workflow/builtins/content-repurpose.d.ts +0 -11
- package/dist/src/agent/workflow/builtins/content-repurpose.js +0 -146
- package/dist/src/agent/workflow/builtins/content-repurpose.js.map +0 -1
- package/dist/src/agent/workflow/builtins/debug-incident.d.ts +0 -13
- package/dist/src/agent/workflow/builtins/debug-incident.js +0 -177
- package/dist/src/agent/workflow/builtins/debug-incident.js.map +0 -1
- package/dist/src/agent/workflow/builtins/decision-compare.d.ts +0 -13
- package/dist/src/agent/workflow/builtins/decision-compare.js +0 -187
- package/dist/src/agent/workflow/builtins/decision-compare.js.map +0 -1
- package/dist/src/agent/workflow/builtins/implementation-plan.d.ts +0 -12
- package/dist/src/agent/workflow/builtins/implementation-plan.js +0 -185
- package/dist/src/agent/workflow/builtins/implementation-plan.js.map +0 -1
- package/dist/src/agent/workflow/builtins/inbox-triage.d.ts +0 -11
- package/dist/src/agent/workflow/builtins/inbox-triage.js +0 -158
- package/dist/src/agent/workflow/builtins/inbox-triage.js.map +0 -1
- package/dist/src/agent/workflow/builtins/meeting-prep.d.ts +0 -12
- package/dist/src/agent/workflow/builtins/meeting-prep.js +0 -152
- package/dist/src/agent/workflow/builtins/meeting-prep.js.map +0 -1
- package/dist/src/agent/workflow/builtins/multi-perspective-review.d.ts +0 -14
- package/dist/src/agent/workflow/builtins/multi-perspective-review.js +0 -171
- package/dist/src/agent/workflow/builtins/multi-perspective-review.js.map +0 -1
- package/dist/src/agent/workflow/builtins/offer-design.d.ts +0 -12
- package/dist/src/agent/workflow/builtins/offer-design.js +0 -170
- package/dist/src/agent/workflow/builtins/offer-design.js.map +0 -1
- package/dist/src/agent/workflow/builtins/pr-review.d.ts +0 -12
- package/dist/src/agent/workflow/builtins/pr-review.js +0 -178
- package/dist/src/agent/workflow/builtins/pr-review.js.map +0 -1
- package/dist/src/agent/workflow/builtins/release-check.d.ts +0 -11
- package/dist/src/agent/workflow/builtins/release-check.js +0 -174
- package/dist/src/agent/workflow/builtins/release-check.js.map +0 -1
- package/dist/src/agent/workflow/builtins/research.d.ts +0 -13
- package/dist/src/agent/workflow/builtins/research.js +0 -188
- package/dist/src/agent/workflow/builtins/research.js.map +0 -1
- package/dist/src/agent/workflow/builtins/weekly-review.d.ts +0 -12
- package/dist/src/agent/workflow/builtins/weekly-review.js +0 -139
- package/dist/src/agent/workflow/builtins/weekly-review.js.map +0 -1
- package/dist/src/agent/workflow/last-run-memory.d.ts +0 -42
- package/dist/src/agent/workflow/last-run-memory.js +0 -60
- package/dist/src/agent/workflow/last-run-memory.js.map +0 -1
- package/dist/src/agent/workflow/lint.d.ts +0 -38
- package/dist/src/agent/workflow/lint.js +0 -74
- package/dist/src/agent/workflow/lint.js.map +0 -1
- package/dist/src/agent/workflow/meta-locale.d.ts +0 -12
- package/dist/src/agent/workflow/meta-locale.js +0 -62
- package/dist/src/agent/workflow/meta-locale.js.map +0 -1
- package/dist/src/agent/workflow/parser.d.ts +0 -20
- package/dist/src/agent/workflow/parser.js +0 -152
- package/dist/src/agent/workflow/parser.js.map +0 -1
- package/dist/src/agent/workflow/runtime.d.ts +0 -34
- package/dist/src/agent/workflow/runtime.js +0 -402
- package/dist/src/agent/workflow/runtime.js.map +0 -1
- package/dist/src/connectors/oauth.d.ts +0 -22
- package/dist/src/connectors/oauth.js +0 -99
- package/dist/src/connectors/oauth.js.map +0 -1
- package/dist/src/workflows/runtime/script-runtime.d.ts +0 -3
- package/dist/src/workflows/runtime/script-runtime.js +0 -3
- package/dist/src/workflows/runtime/script-workflow-runtime.d.ts +0 -5
- package/dist/src/workflows/runtime/script-workflow-runtime.js +0 -15
- package/dist/src/workflows/runtime/script-workflow-runtime.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"goal-service.js","names":[],"sources":["../../../src/goals/goal-service.ts"],"sourcesContent":["import type { Config } from '../config/schema.js';\nimport { defaultMaxTurns } from '../agent/goals/state.js';\nimport { publishAutomationProductEvent } from '../automations/product-events.js';\nimport { GoalStore } from './goal-store.js';\nimport type {\n CreateGoalInput,\n Goal,\n GoalChecklistAddedBy,\n GoalChecklistStatus,\n GoalContextAttachment,\n GoalContractInput,\n GoalEvidenceRequirementStatus,\n GoalEvidenceReviewSource,\n GoalJudgeDecision,\n GoalListQuery,\n GoalSource,\n GoalStatus,\n GoalUiLocale,\n GoalWithDetails,\n} from './types.js';\n\nfunction normalizeTitle(title: string): string {\n const t = title.trim();\n if (!t) throw new Error('Goal title is required');\n return t;\n}\n\nfunction toTerminalStatus(verdict: GoalJudgeDecision['verdict']): GoalStatus {\n if (verdict === 'done') return 'done';\n if (verdict === 'blocked') return 'blocked';\n if (verdict === 'needs_input') return 'needs_input';\n return 'active';\n}\n\nfunction publishGoalEvent(\n type: 'goal.created' | 'goal.status_changed',\n goal: Goal,\n extra?: Record<string, unknown>,\n): void {\n publishAutomationProductEvent({\n type,\n source: 'goals',\n payload: {\n goalId: goal.id,\n title: goal.title,\n status: goal.status,\n priority: goal.priority,\n sessionKey: goal.activeSessionKey,\n agentId: goal.agentId,\n source: goal.source,\n ...extra,\n },\n });\n}\n\nfunction publishGoalStatusEvent(\n goal: Goal,\n previousStatus?: GoalStatus,\n reason?: string,\n): void {\n if (previousStatus === goal.status) return;\n publishGoalEvent('goal.status_changed', goal, {\n previousStatus,\n reason,\n });\n}\n\nexport class GoalService {\n private readonly store: GoalStore;\n\n constructor(store = new GoalStore()) {\n this.store = store;\n }\n\n create(input: Omit<CreateGoalInput, 'maxTurns' | 'agentId'> & {\n maxTurns?: number;\n agentId?: string;\n config?: Config;\n }): Goal {\n const sessionKey = input.sessionKey;\n const cfg = input.config?.goals;\n const goal = this.store.create({\n title: normalizeTitle(input.title),\n description: input.description,\n agentId: input.agentId ?? 'main',\n sessionKey,\n priority: input.priority,\n deadlineAt: input.deadlineAt,\n judgeModelRef: input.judgeModelRef ?? cfg?.judgeModelRef,\n maxTurns: input.maxTurns ?? defaultMaxTurns(cfg),\n uiLocale: input.uiLocale,\n source: input.source,\n projectId: input.projectId,\n contract: input.contract,\n });\n publishGoalEvent('goal.created', goal);\n return goal;\n }\n\n get(goalId: string): GoalWithDetails | null {\n const goal = this.store.get(goalId);\n if (!goal) return null;\n return {\n ...goal,\n checklist: this.store.listChecklist(goalId),\n latestRun: this.store.listRuns(goalId, 1)[0],\n contextMessage: this.store.getContextMessage(goalId) ?? undefined,\n contract: this.store.getContract(goalId) ?? undefined,\n evidenceRequirements: this.store.listEvidenceRequirements(goalId),\n };\n }\n\n getActiveForSession(sessionKey: string): GoalWithDetails | null {\n const goal = this.store.getActiveForSession(sessionKey);\n return goal ? this.get(goal.id) : null;\n }\n\n list(query: GoalListQuery = {}): GoalWithDetails[] {\n return this.store.list(query).map((goal) => ({\n ...goal,\n checklist: this.store.listChecklist(goal.id),\n latestRun: this.store.listRuns(goal.id, 1)[0],\n contextMessage: this.store.getContextMessage(goal.id) ?? undefined,\n contract: this.store.getContract(goal.id) ?? undefined,\n evidenceRequirements: this.store.listEvidenceRequirements(goal.id),\n }));\n }\n\n setContextMessage(input: {\n goalId: string;\n text: string;\n attachments?: GoalContextAttachment[];\n }): GoalWithDetails | null {\n if (!this.store.get(input.goalId)) return null;\n this.store.setContextMessage(input);\n return this.get(input.goalId);\n }\n\n setContract(goalId: string, input: GoalContractInput): GoalWithDetails | null {\n if (!this.store.get(goalId)) return null;\n this.store.setContract(goalId, input);\n if (input.criteria) {\n this.store.replaceChecklist(\n goalId,\n input.criteria\n .map((text) => text.trim())\n .filter(Boolean)\n .map((text) => ({ text, status: 'pending', addedBy: 'user' })),\n );\n }\n return this.get(goalId);\n }\n\n update(goalId: string, patch: Partial<Pick<\n Goal,\n | 'title'\n | 'description'\n | 'priority'\n | 'deadlineAt'\n | 'maxTurns'\n | 'judgeModelRef'\n | 'nextAction'\n | 'blockedReason'\n | 'activeSessionKey'\n | 'uiLocale'\n | 'projectId'\n >>): GoalWithDetails | null {\n const normalized: typeof patch = { ...patch };\n if (typeof normalized.title === 'string') {\n normalized.title = normalizeTitle(normalized.title);\n }\n if (typeof normalized.description === 'string') {\n normalized.description = normalized.description.trim() || undefined;\n }\n if (typeof normalized.judgeModelRef === 'string') {\n normalized.judgeModelRef = normalized.judgeModelRef.trim() || undefined;\n }\n if (typeof normalized.nextAction === 'string') {\n normalized.nextAction = normalized.nextAction.trim() || undefined;\n }\n if (typeof normalized.blockedReason === 'string') {\n normalized.blockedReason = normalized.blockedReason.trim() || undefined;\n }\n if (typeof normalized.maxTurns === 'number') {\n normalized.maxTurns = Math.max(1, Math.min(500, Math.floor(normalized.maxTurns)));\n }\n const goal = this.store.update(goalId, normalized);\n return goal ? this.get(goal.id) : null;\n }\n\n setStatus(goalId: string, status: GoalStatus, opts?: { reason?: string }): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const now = Date.now();\n const goal = this.store.update(goalId, {\n status,\n completedAt: status === 'done' ? now : undefined,\n archivedAt: status === 'archived' ? now : undefined,\n blockedReason: status === 'blocked' || status === 'needs_input' ? opts?.reason : undefined,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status, opts?.reason);\n return goal ? this.get(goal.id) : null;\n }\n\n pause(goalId: string, reason = 'user-paused'): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const goal = this.store.update(goalId, {\n status: 'paused',\n blockedReason: reason,\n completedAt: undefined,\n archivedAt: undefined,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status, reason);\n return goal ? this.get(goal.id) : null;\n }\n\n resume(goalId: string): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const goal = this.store.update(goalId, {\n status: 'active',\n blockedReason: undefined,\n completedAt: undefined,\n archivedAt: undefined,\n turnsUsed: 0,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status);\n return goal ? this.get(goal.id) : null;\n }\n\n reopen(goalId: string): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const goal = this.store.update(goalId, {\n status: 'active',\n blockedReason: undefined,\n completedAt: undefined,\n archivedAt: undefined,\n turnsUsed: 0,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status);\n return goal ? this.get(goal.id) : null;\n }\n\n complete(goalId: string): GoalWithDetails | null {\n return this.setStatus(goalId, 'done');\n }\n\n archive(goalId: string): GoalWithDetails | null {\n return this.setStatus(goalId, 'archived');\n }\n\n unarchive(goalId: string): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const goal = this.store.update(goalId, {\n status: 'paused',\n archivedAt: undefined,\n completedAt: undefined,\n blockedReason: undefined,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status);\n return goal ? this.get(goal.id) : null;\n }\n\n attachSession(goalId: string, sessionKey: string): GoalWithDetails | null {\n const goal = this.store.update(goalId, { activeSessionKey: sessionKey });\n return goal ? this.get(goal.id) : null;\n }\n\n updateChecklist(goalId: string, op: {\n type: 'add';\n text: string;\n addedBy?: GoalChecklistAddedBy;\n } | {\n type: 'mark';\n itemId: string;\n status: GoalChecklistStatus;\n evidenceSummary?: string;\n } | {\n type: 'remove';\n itemId: string;\n } | {\n type: 'reset';\n }): GoalWithDetails | null {\n if (op.type === 'add') {\n const text = op.text.trim();\n if (!text) throw new Error('Checklist item text is required');\n this.store.addChecklistItem({ goalId, text, addedBy: op.addedBy ?? 'user' });\n } else if (op.type === 'mark') {\n this.store.updateChecklistItem(op.itemId, {\n status: op.status,\n evidenceSummary: op.evidenceSummary,\n });\n } else if (op.type === 'remove') {\n this.store.removeChecklistItem(op.itemId);\n } else {\n this.store.clearChecklist(goalId);\n }\n return this.get(goalId);\n }\n\n recordJudgeDecision(input: {\n goalId: string;\n sessionKey: string;\n source: GoalSource;\n decision: GoalJudgeDecision;\n }): GoalWithDetails | null {\n const goal = this.store.get(input.goalId);\n if (!goal) return null;\n const previousStatus = goal.status;\n const nextStatus = toTerminalStatus(input.decision.verdict);\n const turnsUsed = goal.turnsUsed + 1;\n const status = turnsUsed >= goal.maxTurns && nextStatus === 'active' ? 'paused' : nextStatus;\n const reason =\n status === 'paused' && turnsUsed >= goal.maxTurns\n ? `turn budget exhausted (${turnsUsed}/${goal.maxTurns})`\n : input.decision.reason;\n\n const run = this.store.appendRun({\n goalId: input.goalId,\n sessionKey: input.sessionKey,\n source: input.source,\n status: 'succeeded',\n finishedAt: Date.now(),\n verdict: input.decision.verdict,\n reason: input.decision.reason,\n nextAction: input.decision.nextAction,\n assistantPreview: input.decision.assistantPreview,\n checklistProgress: input.decision.checklistProgress,\n confidence: input.decision.confidence,\n missingEvidence: input.decision.missingEvidence,\n userQuestion: input.decision.userQuestion,\n completedChecklistItemIds: input.decision.completedChecklistItemIds,\n });\n\n const updated = this.store.update(input.goalId, {\n status,\n turnsUsed,\n currentRunId: run.id,\n nextAction: input.decision.nextAction,\n blockedReason: status === 'blocked' || status === 'needs_input' || status === 'paused' ? reason : undefined,\n completedAt: status === 'done' ? Date.now() : undefined,\n });\n if (updated) publishGoalStatusEvent(updated, previousStatus, reason);\n\n return this.get(input.goalId);\n }\n\n syncPostTurnState(input: {\n goalId: string;\n sessionKey: string;\n source: GoalSource;\n status: GoalStatus;\n turnsUsed: number;\n maxTurns: number;\n reason?: string;\n nextAction?: string;\n assistantPreview?: string;\n verdict: 'continue' | 'done' | 'blocked' | 'needs_input' | 'decompose';\n confidence?: number;\n missingEvidence?: string[];\n userQuestion?: string;\n completedChecklistItemIds?: string[];\n checklist?: Array<{\n text: string;\n status: 'pending' | 'completed' | 'impossible';\n addedBy: 'user' | 'judge';\n addedAt?: number;\n completedAt?: number;\n evidenceSummary?: string;\n }>;\n }): GoalWithDetails | null {\n const goal = this.store.get(input.goalId);\n if (!goal) return null;\n const previousStatus = goal.status;\n if (input.checklist) {\n this.store.replaceChecklist(input.goalId, input.checklist);\n }\n const total = input.checklist?.length ?? this.store.listChecklist(input.goalId).length;\n const done = (input.checklist ?? this.store.listChecklist(input.goalId)).filter(\n (it) => it.status === 'completed' || it.status === 'impossible',\n ).length;\n const run = this.store.appendRun({\n goalId: input.goalId,\n sessionKey: input.sessionKey,\n source: input.source,\n status: 'succeeded',\n finishedAt: Date.now(),\n verdict: input.verdict,\n reason: input.reason,\n nextAction: input.nextAction,\n assistantPreview: input.assistantPreview,\n checklistProgress: total > 0 ? { done, total } : undefined,\n confidence: input.confidence,\n missingEvidence: input.missingEvidence,\n userQuestion: input.userQuestion,\n completedChecklistItemIds: input.completedChecklistItemIds,\n });\n for (const item of input.checklist ?? []) {\n if ((item.status === 'completed' || item.status === 'impossible') && item.evidenceSummary?.trim()) {\n this.store.addEvidence({\n goalId: input.goalId,\n runId: run.id,\n kind: 'message',\n title: `Checklist evidence: ${item.text.slice(0, 80)}`,\n summary: item.evidenceSummary.trim(),\n });\n }\n }\n for (const missing of input.missingEvidence ?? []) {\n if (!missing.trim()) continue;\n this.store.addEvidence({\n goalId: input.goalId,\n runId: run.id,\n kind: 'message',\n title: `Missing evidence: ${missing.slice(0, 80)}`,\n summary: missing,\n });\n }\n if (input.userQuestion?.trim()) {\n this.store.addEvidence({\n goalId: input.goalId,\n runId: run.id,\n kind: 'message',\n title: 'User input requested',\n summary: input.userQuestion.trim(),\n });\n }\n const updated = this.store.update(input.goalId, {\n status: input.status,\n turnsUsed: input.turnsUsed,\n maxTurns: input.maxTurns,\n currentRunId: run.id,\n nextAction: input.nextAction,\n blockedReason:\n input.status === 'blocked' || input.status === 'needs_input' || input.status === 'paused'\n ? input.reason\n : undefined,\n completedAt: input.status === 'done' ? Date.now() : undefined,\n });\n if (updated) publishGoalStatusEvent(updated, previousStatus, input.reason);\n return this.get(input.goalId);\n }\n\n listRuns(goalId: string, limit?: number) {\n return this.store.listRuns(goalId, limit);\n }\n\n listRunsForSession(sessionKey: string, limit?: number) {\n return this.store.listRunsForSession(sessionKey, limit);\n }\n\n listEvents(goalId: string, limit?: number) {\n return this.store.listEvents(goalId, limit);\n }\n\n addEvidence(input: Parameters<GoalStore['addEvidence']>[0]) {\n return this.store.addEvidence(input);\n }\n\n listEvidence(goalId: string, limit?: number) {\n return this.store.listEvidence(goalId, limit);\n }\n\n listEvidenceRequirements(goalId: string) {\n return this.store.listEvidenceRequirements(goalId);\n }\n\n linkEvidenceRequirement(input: Parameters<GoalStore['linkEvidenceRequirement']>[0]) {\n return this.store.linkEvidenceRequirement(input);\n }\n\n reviewEvidenceRequirement(input: {\n goalId: string;\n requirementId: string;\n status: GoalEvidenceRequirementStatus;\n reason: string;\n confidence?: number;\n reviewedBy: GoalEvidenceReviewSource;\n }) {\n return this.store.reviewEvidenceRequirement(input);\n }\n\n getCompletionReadiness(goalId: string): { ready: boolean; missingEvidence: string[]; pendingApproval: string[] } | null {\n const goal = this.get(goalId);\n if (!goal) return null;\n const required = goal.evidenceRequirements;\n if (!required.length) return { ready: true, missingEvidence: [], pendingApproval: [] };\n const missingEvidence = required.filter((item) => item.evidenceIds.length === 0).map((item) => item.text);\n const pendingApproval = required\n .filter((item) => item.evidenceIds.length > 0 && item.status !== 'approved')\n .map((item) => item.text);\n return {\n ready: missingEvidence.length === 0 && pendingApproval.length === 0,\n missingEvidence,\n pendingApproval,\n };\n }\n}\n\nexport function normalizeGoalUiLocale(raw: unknown): GoalUiLocale | undefined {\n return raw === 'en' || raw === 'zh' ? raw : undefined;\n}\n"],"mappings":";;;;AAqBA,SAAS,eAAe,OAAuB;CAC7C,MAAM,IAAI,MAAM,MAAM;AACtB,KAAI,CAAC,EAAG,OAAM,IAAI,MAAM,yBAAyB;AACjD,QAAO;;AAGT,SAAS,iBAAiB,SAAmD;AAC3E,KAAI,YAAY,OAAQ,QAAO;AAC/B,KAAI,YAAY,UAAW,QAAO;AAClC,KAAI,YAAY,cAAe,QAAO;AACtC,QAAO;;AAGT,SAAS,iBACP,MACA,MACA,OACM;AACN,+BAA8B;EAC5B;EACA,QAAQ;EACR,SAAS;GACP,QAAQ,KAAK;GACb,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,UAAU,KAAK;GACf,YAAY,KAAK;GACjB,SAAS,KAAK;GACd,QAAQ,KAAK;GACb,GAAG;GACJ;EACF,CAAC;;AAGJ,SAAS,uBACP,MACA,gBACA,QACM;AACN,KAAI,mBAAmB,KAAK,OAAQ;AACpC,kBAAiB,uBAAuB,MAAM;EAC5C;EACA;EACD,CAAC;;AAGJ,IAAa,cAAb,MAAyB;CACvB;CAEA,YAAY,QAAQ,IAAI,WAAW,EAAE;AACnC,OAAK,QAAQ;;CAGf,OAAO,OAIE;EACP,MAAM,aAAa,MAAM;EACzB,MAAM,MAAM,MAAM,QAAQ;EAC1B,MAAM,OAAO,KAAK,MAAM,OAAO;GAC7B,OAAO,eAAe,MAAM,MAAM;G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OAAgB;AACvC,SAAO,KAAK,MAAM,SAAS,QAAQ,MAAM;;CAG3C,mBAAmB,YAAoB,OAAgB;AACrD,SAAO,KAAK,MAAM,mBAAmB,YAAY,MAAM;;CAGzD,WAAW,QAAgB,OAAgB;AACzC,SAAO,KAAK,MAAM,WAAW,QAAQ,MAAM;;CAG7C,YAAY,OAAgD;AAC1D,SAAO,KAAK,MAAM,YAAY,MAAM;;CAGtC,aAAa,QAAgB,OAAgB;AAC3C,SAAO,KAAK,MAAM,aAAa,QAAQ,MAAM;;CAG/C,yBAAyB,QAAgB;AACvC,SAAO,KAAK,MAAM,yBAAyB,OAAO;;CAGpD,wBAAwB,OAA4D;AAClF,SAAO,KAAK,MAAM,wBAAwB,MAAM;;CAGlD,0BAA0B,OAOvB;AACD,SAAO,KAAK,MAAM,0BAA0B,MAAM;;CAGpD,uBAAuB,QAAiG;EACtH,MAAM,OAAO,KAAK,IAAI,OAAO;AAC7B,MAAI,CAAC,KAAM,QAAO;EAClB,MAAM,WAAW,KAAK;AACtB,MAAI,CAAC,SAAS,OAAQ,QAAO;GAAE,OAAO;GAAM,iBAAiB,EAAE;GAAE,iBAAiB,EAAE;GAAE;EACtF,MAAM,kBAAkB,SAAS,QAAQ,SAAS,KAAK,YAAY,WAAW,EAAE,CAAC,KAAK,SAAS,KAAK,KAAK;EACzG,MAAM,kBAAkB,SACrB,QAAQ,SAAS,KAAK,YAAY,SAAS,KAAK,KAAK,WAAW,WAAW,CAC3E,KAAK,SAAS,KAAK,KAAK;AAC3B,SAAO;GACL,OAAO,gBAAgB,WAAW,KAAK,gBAAgB,WAAW;GAClE;GACA;GACD;;;AAIL,SAAgB,sBAAsB,KAAwC;AAC5E,QAAO,QAAQ,QAAQ,QAAQ,OAAO,MAAM,KAAA"}
|
|
1
|
+
{"version":3,"file":"goal-service.js","names":[],"sources":["../../../src/goals/goal-service.ts"],"sourcesContent":["import type { Config } from '../config/schema.js';\nimport { defaultMaxTurns } from '../agent/goals/state.js';\nimport { publishAutomationProductEvent } from '../automations/product-events.js';\nimport { GoalStore } from './goal-store.js';\nimport type {\n CreateGoalInput,\n Goal,\n GoalChecklistAddedBy,\n GoalChecklistStatus,\n GoalContextAttachment,\n GoalContractInput,\n GoalEvidenceRequirementStatus,\n GoalEvidenceReviewSource,\n GoalJudgeDecision,\n GoalListQuery,\n GoalSource,\n GoalStatus,\n GoalUiLocale,\n GoalWithDetails,\n} from './types.js';\n\nfunction normalizeTitle(title: string): string {\n const t = title.trim();\n if (!t) throw new Error('Goal title is required');\n return t;\n}\n\nfunction toTerminalStatus(verdict: GoalJudgeDecision['verdict']): GoalStatus {\n if (verdict === 'done') return 'done';\n if (verdict === 'blocked') return 'blocked';\n if (verdict === 'needs_input') return 'needs_input';\n return 'active';\n}\n\nexport interface GoalCompletionReadiness {\n ready: boolean;\n missingEvidence: string[];\n pendingApproval: string[];\n pendingOutcome: string[];\n}\n\nfunction completionReviewReason(readiness: GoalCompletionReadiness): string {\n const pending = [\n ...readiness.missingEvidence,\n ...readiness.pendingApproval,\n ...readiness.pendingOutcome,\n ];\n return pending.length\n ? `Completion review required: ${pending.join('; ')}`\n : 'Completion review required.';\n}\n\nfunction publishGoalEvent(\n type: 'goal.created' | 'goal.status_changed',\n goal: Goal,\n extra?: Record<string, unknown>,\n): void {\n publishAutomationProductEvent({\n type,\n source: 'goals',\n payload: {\n goalId: goal.id,\n title: goal.title,\n status: goal.status,\n priority: goal.priority,\n sessionKey: goal.activeSessionKey,\n agentId: goal.agentId,\n source: goal.source,\n ...extra,\n },\n });\n}\n\nfunction publishGoalStatusEvent(\n goal: Goal,\n previousStatus?: GoalStatus,\n reason?: string,\n): void {\n if (previousStatus === goal.status) return;\n publishGoalEvent('goal.status_changed', goal, {\n previousStatus,\n reason,\n });\n}\n\nexport class GoalService {\n private readonly store: GoalStore;\n\n constructor(store = new GoalStore()) {\n this.store = store;\n }\n\n create(input: Omit<CreateGoalInput, 'maxTurns' | 'agentId'> & {\n maxTurns?: number;\n agentId?: string;\n config?: Config;\n }): Goal {\n const sessionKey = input.sessionKey;\n const cfg = input.config?.goals;\n const goal = this.store.create({\n title: normalizeTitle(input.title),\n description: input.description,\n agentId: input.agentId ?? 'main',\n sessionKey,\n priority: input.priority,\n deadlineAt: input.deadlineAt,\n judgeModelRef: input.judgeModelRef ?? cfg?.judgeModelRef,\n maxTurns: input.maxTurns ?? defaultMaxTurns(cfg),\n uiLocale: input.uiLocale,\n source: input.source,\n projectId: input.projectId,\n contract: input.contract,\n });\n publishGoalEvent('goal.created', goal);\n return goal;\n }\n\n get(goalId: string): GoalWithDetails | null {\n const goal = this.store.get(goalId);\n if (!goal) return null;\n return {\n ...goal,\n checklist: this.store.listChecklist(goalId),\n latestRun: this.store.listRuns(goalId, 1)[0],\n contextMessage: this.store.getContextMessage(goalId) ?? undefined,\n contract: this.store.getContract(goalId) ?? undefined,\n evidenceRequirements: this.store.listEvidenceRequirements(goalId),\n };\n }\n\n getActiveForSession(sessionKey: string): GoalWithDetails | null {\n const goal = this.store.getActiveForSession(sessionKey);\n return goal ? this.get(goal.id) : null;\n }\n\n list(query: GoalListQuery = {}): GoalWithDetails[] {\n return this.store.list(query).map((goal) => ({\n ...goal,\n checklist: this.store.listChecklist(goal.id),\n latestRun: this.store.listRuns(goal.id, 1)[0],\n contextMessage: this.store.getContextMessage(goal.id) ?? undefined,\n contract: this.store.getContract(goal.id) ?? undefined,\n evidenceRequirements: this.store.listEvidenceRequirements(goal.id),\n }));\n }\n\n setContextMessage(input: {\n goalId: string;\n text: string;\n attachments?: GoalContextAttachment[];\n }): GoalWithDetails | null {\n if (!this.store.get(input.goalId)) return null;\n this.store.setContextMessage(input);\n return this.get(input.goalId);\n }\n\n setContract(goalId: string, input: GoalContractInput): GoalWithDetails | null {\n if (!this.store.get(goalId)) return null;\n this.store.setContract(goalId, input);\n if (input.criteria) {\n this.store.replaceChecklist(\n goalId,\n input.criteria\n .map((text) => text.trim())\n .filter(Boolean)\n .map((text) => ({ text, status: 'pending', addedBy: 'user' })),\n );\n }\n return this.get(goalId);\n }\n\n update(goalId: string, patch: Partial<Pick<\n Goal,\n | 'title'\n | 'description'\n | 'priority'\n | 'deadlineAt'\n | 'maxTurns'\n | 'judgeModelRef'\n | 'nextAction'\n | 'blockedReason'\n | 'activeSessionKey'\n | 'uiLocale'\n | 'projectId'\n >>): GoalWithDetails | null {\n const normalized: typeof patch = { ...patch };\n if (typeof normalized.title === 'string') {\n normalized.title = normalizeTitle(normalized.title);\n }\n if (typeof normalized.description === 'string') {\n normalized.description = normalized.description.trim() || undefined;\n }\n if (typeof normalized.judgeModelRef === 'string') {\n normalized.judgeModelRef = normalized.judgeModelRef.trim() || undefined;\n }\n if (typeof normalized.nextAction === 'string') {\n normalized.nextAction = normalized.nextAction.trim() || undefined;\n }\n if (typeof normalized.blockedReason === 'string') {\n normalized.blockedReason = normalized.blockedReason.trim() || undefined;\n }\n if (typeof normalized.maxTurns === 'number') {\n normalized.maxTurns = Math.max(1, Math.min(500, Math.floor(normalized.maxTurns)));\n }\n const goal = this.store.update(goalId, normalized);\n return goal ? this.get(goal.id) : null;\n }\n\n setStatus(goalId: string, status: GoalStatus, opts?: { reason?: string }): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const now = Date.now();\n const goal = this.store.update(goalId, {\n status,\n completedAt: status === 'done' ? now : undefined,\n archivedAt: status === 'archived' ? now : undefined,\n blockedReason: status === 'blocked' || status === 'needs_input' ? opts?.reason : undefined,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status, opts?.reason);\n return goal ? this.get(goal.id) : null;\n }\n\n pause(goalId: string, reason = 'user-paused'): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const goal = this.store.update(goalId, {\n status: 'paused',\n blockedReason: reason,\n completedAt: undefined,\n archivedAt: undefined,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status, reason);\n return goal ? this.get(goal.id) : null;\n }\n\n resume(goalId: string): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const goal = this.store.update(goalId, {\n status: 'active',\n blockedReason: undefined,\n completedAt: undefined,\n archivedAt: undefined,\n turnsUsed: 0,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status);\n return goal ? this.get(goal.id) : null;\n }\n\n reopen(goalId: string): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const goal = this.store.update(goalId, {\n status: 'active',\n blockedReason: undefined,\n completedAt: undefined,\n archivedAt: undefined,\n turnsUsed: 0,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status);\n return goal ? this.get(goal.id) : null;\n }\n\n complete(goalId: string): GoalWithDetails | null {\n return this.setStatus(goalId, 'done');\n }\n\n archive(goalId: string): GoalWithDetails | null {\n return this.setStatus(goalId, 'archived');\n }\n\n unarchive(goalId: string): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const goal = this.store.update(goalId, {\n status: 'paused',\n archivedAt: undefined,\n completedAt: undefined,\n blockedReason: undefined,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status);\n return goal ? this.get(goal.id) : null;\n }\n\n attachSession(goalId: string, sessionKey: string): GoalWithDetails | null {\n const goal = this.store.update(goalId, { activeSessionKey: sessionKey });\n return goal ? this.get(goal.id) : null;\n }\n\n updateChecklist(goalId: string, op: {\n type: 'add';\n text: string;\n addedBy?: GoalChecklistAddedBy;\n } | {\n type: 'mark';\n itemId: string;\n status: GoalChecklistStatus;\n evidenceSummary?: string;\n } | {\n type: 'remove';\n itemId: string;\n } | {\n type: 'reset';\n }): GoalWithDetails | null {\n if (op.type === 'add') {\n const text = op.text.trim();\n if (!text) throw new Error('Checklist item text is required');\n this.store.addChecklistItem({ goalId, text, addedBy: op.addedBy ?? 'user' });\n } else if (op.type === 'mark') {\n this.store.updateChecklistItem(op.itemId, {\n status: op.status,\n evidenceSummary: op.evidenceSummary,\n });\n } else if (op.type === 'remove') {\n this.store.removeChecklistItem(op.itemId);\n } else {\n this.store.clearChecklist(goalId);\n }\n return this.get(goalId);\n }\n\n recordJudgeDecision(input: {\n goalId: string;\n sessionKey: string;\n source: GoalSource;\n decision: GoalJudgeDecision;\n }): GoalWithDetails | null {\n const goal = this.store.get(input.goalId);\n if (!goal) return null;\n const previousStatus = goal.status;\n const nextStatus = toTerminalStatus(input.decision.verdict);\n const turnsUsed = goal.turnsUsed + 1;\n const budgetStatus = turnsUsed >= goal.maxTurns && nextStatus === 'active' ? 'paused' : nextStatus;\n const readiness = budgetStatus === 'done' ? this.getCompletionReadiness(input.goalId) : null;\n const status = readiness && !readiness.ready ? 'needs_input' : budgetStatus;\n const reason = readiness && !readiness.ready\n ? completionReviewReason(readiness)\n : status === 'paused' && turnsUsed >= goal.maxTurns\n ? `turn budget exhausted (${turnsUsed}/${goal.maxTurns})`\n : input.decision.reason;\n\n const run = this.store.appendRun({\n goalId: input.goalId,\n sessionKey: input.sessionKey,\n source: input.source,\n status: 'succeeded',\n finishedAt: Date.now(),\n verdict: input.decision.verdict,\n reason: input.decision.reason,\n nextAction: input.decision.nextAction,\n assistantPreview: input.decision.assistantPreview,\n checklistProgress: input.decision.checklistProgress,\n confidence: input.decision.confidence,\n missingEvidence: input.decision.missingEvidence,\n userQuestion: input.decision.userQuestion,\n completedChecklistItemIds: input.decision.completedChecklistItemIds,\n });\n\n const updated = this.store.update(input.goalId, {\n status,\n turnsUsed,\n currentRunId: run.id,\n nextAction: input.decision.nextAction,\n blockedReason: status === 'blocked' || status === 'needs_input' || status === 'paused' ? reason : undefined,\n completedAt: status === 'done' ? Date.now() : undefined,\n });\n if (updated) publishGoalStatusEvent(updated, previousStatus, reason);\n\n return this.get(input.goalId);\n }\n\n syncPostTurnState(input: {\n goalId: string;\n sessionKey: string;\n source: GoalSource;\n status: GoalStatus;\n turnsUsed: number;\n maxTurns: number;\n reason?: string;\n nextAction?: string;\n assistantPreview?: string;\n verdict: 'continue' | 'done' | 'blocked' | 'needs_input' | 'decompose';\n confidence?: number;\n missingEvidence?: string[];\n userQuestion?: string;\n completedChecklistItemIds?: string[];\n checklist?: Array<{\n text: string;\n status: 'pending' | 'completed' | 'impossible';\n addedBy: 'user' | 'judge';\n addedAt?: number;\n completedAt?: number;\n evidenceSummary?: string;\n }>;\n }): GoalWithDetails | null {\n const goal = this.store.get(input.goalId);\n if (!goal) return null;\n const previousStatus = goal.status;\n if (input.checklist) {\n this.store.replaceChecklist(input.goalId, input.checklist);\n }\n const total = input.checklist?.length ?? this.store.listChecklist(input.goalId).length;\n const done = (input.checklist ?? this.store.listChecklist(input.goalId)).filter(\n (it) => it.status === 'completed' || it.status === 'impossible',\n ).length;\n const run = this.store.appendRun({\n goalId: input.goalId,\n sessionKey: input.sessionKey,\n source: input.source,\n status: 'succeeded',\n finishedAt: Date.now(),\n verdict: input.verdict,\n reason: input.reason,\n nextAction: input.nextAction,\n assistantPreview: input.assistantPreview,\n checklistProgress: total > 0 ? { done, total } : undefined,\n confidence: input.confidence,\n missingEvidence: input.missingEvidence,\n userQuestion: input.userQuestion,\n completedChecklistItemIds: input.completedChecklistItemIds,\n });\n for (const item of input.checklist ?? []) {\n if ((item.status === 'completed' || item.status === 'impossible') && item.evidenceSummary?.trim()) {\n this.store.addEvidence({\n goalId: input.goalId,\n runId: run.id,\n kind: 'message',\n title: `Checklist evidence: ${item.text.slice(0, 80)}`,\n summary: item.evidenceSummary.trim(),\n });\n }\n }\n for (const missing of input.missingEvidence ?? []) {\n if (!missing.trim()) continue;\n this.store.addEvidence({\n goalId: input.goalId,\n runId: run.id,\n kind: 'message',\n title: `Missing evidence: ${missing.slice(0, 80)}`,\n summary: missing,\n });\n }\n if (input.userQuestion?.trim()) {\n this.store.addEvidence({\n goalId: input.goalId,\n runId: run.id,\n kind: 'message',\n title: 'User input requested',\n summary: input.userQuestion.trim(),\n });\n }\n const readiness = input.status === 'done' ? this.getCompletionReadiness(input.goalId) : null;\n const status = readiness && !readiness.ready ? 'needs_input' : input.status;\n const completionReason = readiness && !readiness.ready ? completionReviewReason(readiness) : input.reason;\n const updated = this.store.update(input.goalId, {\n status,\n turnsUsed: input.turnsUsed,\n maxTurns: input.maxTurns,\n currentRunId: run.id,\n nextAction: input.nextAction,\n blockedReason:\n status === 'blocked' || status === 'needs_input' || status === 'paused'\n ? completionReason\n : undefined,\n completedAt: status === 'done' ? Date.now() : undefined,\n });\n if (updated) publishGoalStatusEvent(updated, previousStatus, completionReason);\n return this.get(input.goalId);\n }\n\n listRuns(goalId: string, limit?: number) {\n return this.store.listRuns(goalId, limit);\n }\n\n listRunsForSession(sessionKey: string, limit?: number) {\n return this.store.listRunsForSession(sessionKey, limit);\n }\n\n listEvents(goalId: string, limit?: number) {\n return this.store.listEvents(goalId, limit);\n }\n\n addEvidence(input: Parameters<GoalStore['addEvidence']>[0]) {\n return this.store.addEvidence(input);\n }\n\n listEvidence(goalId: string, limit?: number) {\n return this.store.listEvidence(goalId, limit);\n }\n\n listEvidenceRequirements(goalId: string) {\n return this.store.listEvidenceRequirements(goalId);\n }\n\n linkEvidenceRequirement(input: Parameters<GoalStore['linkEvidenceRequirement']>[0]) {\n return this.store.linkEvidenceRequirement(input);\n }\n\n reviewEvidenceRequirement(input: {\n goalId: string;\n requirementId: string;\n status: GoalEvidenceRequirementStatus;\n reason: string;\n confidence?: number;\n reviewedBy: GoalEvidenceReviewSource;\n }) {\n return this.store.reviewEvidenceRequirement(input);\n }\n\n getCompletionReadiness(goalId: string): GoalCompletionReadiness | null {\n const goal = this.get(goalId);\n if (!goal) return null;\n const required = goal.evidenceRequirements;\n const missingEvidence = required.filter((item) => item.evidenceIds.length === 0).map((item) => item.text);\n const pendingApproval = required\n .filter((item) => item.evidenceIds.length > 0 && item.status !== 'approved')\n .map((item) => item.text);\n const metric = goal.contract?.outcomeMetric;\n const outcomeAchieved = metric?.currentValue != null && (\n metric.direction === 'increase'\n ? metric.currentValue >= metric.targetValue\n : metric.currentValue <= metric.targetValue\n );\n const pendingOutcome = metric && !outcomeAchieved\n ? [metric.currentValue == null\n ? `${metric.name}: current value is not recorded`\n : `${metric.name}: current value ${metric.currentValue} has not reached target ${metric.targetValue}`]\n : [];\n return {\n ready: missingEvidence.length === 0 && pendingApproval.length === 0 && pendingOutcome.length === 0,\n missingEvidence,\n pendingApproval,\n pendingOutcome,\n };\n }\n}\n\nexport function normalizeGoalUiLocale(raw: unknown): GoalUiLocale | undefined {\n return raw === 'en' || raw === 'zh' ? raw : undefined;\n}\n"],"mappings":";;;;AAqBA,SAAS,eAAe,OAAuB;CAC7C,MAAM,IAAI,MAAM,MAAM;AACtB,KAAI,CAAC,EAAG,OAAM,IAAI,MAAM,yBAAyB;AACjD,QAAO;;AAGT,SAAS,iBAAiB,SAAmD;AAC3E,KAAI,YAAY,OAAQ,QAAO;AAC/B,KAAI,YAAY,UAAW,QAAO;AAClC,KAAI,YAAY,cAAe,QAAO;AACtC,QAAO;;AAUT,SAAS,uBAAuB,WAA4C;CAC1E,MAAM,UAAU;EACd,GAAG,UAAU;EACb,GAAG,UAAU;EACb,GAAG,UAAU;EACd;AACD,QAAO,QAAQ,SACX,+BAA+B,QAAQ,KAAK,KAAK,KACjD;;AAGN,SAAS,iBACP,MACA,MACA,OACM;AACN,+BAA8B;EAC5B;EACA,QAAQ;EACR,SAAS;GACP,QAAQ,KAAK;GACb,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,UAAU,KAAK;GACf,YAAY,KAAK;GACjB,SAAS,KAAK;GACd,QAAQ,KAAK;GACb,GAAG;GACJ;EACF,CAAC;;AAGJ,SAAS,uBACP,MACA,gBACA,QACM;AACN,KAAI,mBAAmB,KAAK,OAAQ;AACpC,kBAAiB,uBAAuB,MAAM;EAC5C;EACA;EACD,CAAC;;AAGJ,IAAa,cAAb,MAAyB;CACvB;CAEA,YAAY,QAAQ,IAAI,WAAW,EAAE;AACnC,OAAK,QAAQ;;CAGf,OAAO,OAIE;EACP,MAAM,aAAa,MAAM;EACzB,MAAM,MAAM,MAAM,QAAQ;EAC1B,MAAM,OAAO,KAAK,MAAM,OAAO;GAC7B,OAAO,eAAe,MAAM,MAAM;GAClC,aAAa,MAAM;GACn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AO,gBAAgB,OAAO,cAC9B,OAAO,gBAAgB,OAAO;EAEpC,MAAM,iBAAiB,UAAU,CAAC,kBAC9B,CAAC,OAAO,gBAAgB,OACpB,GAAG,OAAO,KAAK,mCACf,GAAG,OAAO,KAAK,kBAAkB,OAAO,aAAa,0BAA0B,OAAO,cAAc,GACxG,EAAE;AACN,SAAO;GACL,OAAO,gBAAgB,WAAW,KAAK,gBAAgB,WAAW,KAAK,eAAe,WAAW;GACjG;GACA;GACA;GACD;;;AAIL,SAAgB,sBAAsB,KAAwC;AAC5E,QAAO,QAAQ,QAAQ,QAAQ,OAAO,MAAM,KAAA"}
|
|
@@ -101,10 +101,40 @@ function goalContractFromRow(row) {
|
|
|
101
101
|
objective: row.objective,
|
|
102
102
|
scopeBoundary: row.scope_boundary ?? void 0,
|
|
103
103
|
evidencePlan: parseJsonStringArray(row.evidence_plan_json) ?? [],
|
|
104
|
+
outcomeMetric: parseGoalOutcomeMetric(row.outcome_metric_json),
|
|
104
105
|
createdAt: row.created_at,
|
|
105
106
|
updatedAt: row.updated_at
|
|
106
107
|
};
|
|
107
108
|
}
|
|
109
|
+
function parseGoalOutcomeMetric(raw) {
|
|
110
|
+
const value = parseJsonField(raw);
|
|
111
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
112
|
+
const metric = value;
|
|
113
|
+
if (typeof metric.name !== "string" || !metric.name.trim() || typeof metric.baselineValue !== "number" || !Number.isFinite(metric.baselineValue) || typeof metric.targetValue !== "number" || !Number.isFinite(metric.targetValue) || metric.direction !== "increase" && metric.direction !== "decrease") return void 0;
|
|
114
|
+
return {
|
|
115
|
+
name: metric.name.trim(),
|
|
116
|
+
baselineValue: metric.baselineValue,
|
|
117
|
+
targetValue: metric.targetValue,
|
|
118
|
+
currentValue: typeof metric.currentValue === "number" && Number.isFinite(metric.currentValue) ? metric.currentValue : void 0,
|
|
119
|
+
unit: typeof metric.unit === "string" && metric.unit.trim() ? metric.unit.trim() : void 0,
|
|
120
|
+
direction: metric.direction,
|
|
121
|
+
sourceUrl: typeof metric.sourceUrl === "string" && metric.sourceUrl.trim() ? metric.sourceUrl.trim() : void 0,
|
|
122
|
+
measuredAt: typeof metric.measuredAt === "number" && Number.isFinite(metric.measuredAt) ? metric.measuredAt : void 0
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function normalizeGoalOutcomeMetric(input) {
|
|
126
|
+
if (!input) return void 0;
|
|
127
|
+
return {
|
|
128
|
+
name: input.name.trim(),
|
|
129
|
+
baselineValue: input.baselineValue,
|
|
130
|
+
targetValue: input.targetValue,
|
|
131
|
+
currentValue: input.currentValue,
|
|
132
|
+
unit: input.unit?.trim() || void 0,
|
|
133
|
+
direction: input.direction ?? (input.targetValue >= input.baselineValue ? "increase" : "decrease"),
|
|
134
|
+
sourceUrl: input.sourceUrl?.trim() || void 0,
|
|
135
|
+
measuredAt: input.measuredAt
|
|
136
|
+
};
|
|
137
|
+
}
|
|
108
138
|
function normalizeStringList(items, limit = 20) {
|
|
109
139
|
if (!items) return [];
|
|
110
140
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -127,14 +157,15 @@ function normalizeContract(input, goalId, fallbackObjective, now, version = 1, c
|
|
|
127
157
|
objective: input.objective?.trim() || fallbackObjective,
|
|
128
158
|
scopeBoundary: input.scopeBoundary?.trim() || void 0,
|
|
129
159
|
evidencePlan: normalizeStringList(input.evidencePlan),
|
|
160
|
+
outcomeMetric: normalizeGoalOutcomeMetric(input.outcomeMetric),
|
|
130
161
|
createdAt,
|
|
131
162
|
updatedAt: now
|
|
132
163
|
};
|
|
133
164
|
}
|
|
134
165
|
function insertGoalContract(db, contract) {
|
|
135
166
|
db.prepare(`INSERT INTO goal_contracts (
|
|
136
|
-
goal_id, version, objective, scope_boundary, evidence_plan_json, created_at, updated_at
|
|
137
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?)`).run(contract.goalId, contract.version, contract.objective, contract.scopeBoundary ?? null, JSON.stringify(contract.evidencePlan), contract.createdAt, contract.updatedAt);
|
|
167
|
+
goal_id, version, objective, scope_boundary, evidence_plan_json, outcome_metric_json, created_at, updated_at
|
|
168
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(contract.goalId, contract.version, contract.objective, contract.scopeBoundary ?? null, JSON.stringify(contract.evidencePlan), contract.outcomeMetric ? JSON.stringify(contract.outcomeMetric) : null, contract.createdAt, contract.updatedAt);
|
|
138
169
|
}
|
|
139
170
|
function eventFromRow(row) {
|
|
140
171
|
return {
|
|
@@ -305,17 +336,24 @@ var GoalStore = class {
|
|
|
305
336
|
return runSqliteWriteTransaction((db) => {
|
|
306
337
|
const existing = db.prepare(`SELECT * FROM goal_contracts WHERE goal_id = ?`).get(goalId);
|
|
307
338
|
const now = Date.now();
|
|
308
|
-
const contract = normalizeContract(
|
|
339
|
+
const contract = normalizeContract({
|
|
340
|
+
...input,
|
|
341
|
+
objective: input.objective ?? existing?.objective,
|
|
342
|
+
scopeBoundary: input.scopeBoundary ?? existing?.scope_boundary ?? void 0,
|
|
343
|
+
evidencePlan: input.evidencePlan ?? parseJsonStringArray(existing?.evidence_plan_json ?? null) ?? [],
|
|
344
|
+
outcomeMetric: input.outcomeMetric === void 0 ? parseGoalOutcomeMetric(existing?.outcome_metric_json ?? null) : input.outcomeMetric
|
|
345
|
+
}, goalId, goal.title, now, (existing?.version ?? 0) + 1, existing?.created_at ?? now);
|
|
309
346
|
if (!contract) return null;
|
|
310
347
|
db.prepare(`INSERT INTO goal_contracts (
|
|
311
|
-
goal_id, version, objective, scope_boundary, evidence_plan_json, created_at, updated_at
|
|
312
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
348
|
+
goal_id, version, objective, scope_boundary, evidence_plan_json, outcome_metric_json, created_at, updated_at
|
|
349
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
313
350
|
ON CONFLICT(goal_id) DO UPDATE SET
|
|
314
351
|
version = excluded.version,
|
|
315
352
|
objective = excluded.objective,
|
|
316
353
|
scope_boundary = excluded.scope_boundary,
|
|
317
354
|
evidence_plan_json = excluded.evidence_plan_json,
|
|
318
|
-
|
|
355
|
+
outcome_metric_json = excluded.outcome_metric_json,
|
|
356
|
+
updated_at = excluded.updated_at`).run(contract.goalId, contract.version, contract.objective, contract.scopeBoundary ?? null, JSON.stringify(contract.evidencePlan), contract.outcomeMetric ? JSON.stringify(contract.outcomeMetric) : null, contract.createdAt, contract.updatedAt);
|
|
319
357
|
syncEvidenceRequirements(db, goalId, contract.evidencePlan, now);
|
|
320
358
|
insertGoalEvent(db, {
|
|
321
359
|
goalId,
|
|
@@ -323,7 +361,8 @@ var GoalStore = class {
|
|
|
323
361
|
message: contract.objective,
|
|
324
362
|
data: {
|
|
325
363
|
version: contract.version,
|
|
326
|
-
evidenceCount: contract.evidencePlan.length
|
|
364
|
+
evidenceCount: contract.evidencePlan.length,
|
|
365
|
+
hasOutcomeMetric: Boolean(contract.outcomeMetric)
|
|
327
366
|
},
|
|
328
367
|
createdAt: now
|
|
329
368
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"goal-store.js","names":[],"sources":["../../../src/goals/goal-store.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport { getSqliteDatabase, runSqliteWriteTransaction } from '../storage/sqlite/transaction.js';\nimport type {\n CreateGoalInput,\n Goal,\n GoalChecklistAddedBy,\n GoalChecklistItem,\n GoalChecklistStatus,\n GoalContextAttachment,\n GoalContextMessage,\n GoalContract,\n GoalContractInput,\n GoalEvent,\n GoalEvidence,\n GoalEvidenceRequirement,\n GoalEvidenceRequirementStatus,\n GoalEvidenceReviewSource,\n GoalListQuery,\n GoalPriority,\n GoalRun,\n GoalRunStatus,\n GoalRunVerdict,\n GoalSource,\n GoalStatus,\n} from './types.js';\n\ntype GoalRow = {\n goal_id: string;\n title: string;\n description: string | null;\n status: string;\n agent_id: string;\n priority: string;\n deadline_at: number | null;\n created_at: number;\n updated_at: number;\n completed_at: number | null;\n archived_at: number | null;\n active_session_key: string | null;\n current_run_id: string | null;\n next_action: string | null;\n blocked_reason: string | null;\n judge_model_ref: string | null;\n max_turns: number;\n turns_used: number;\n ui_locale: string | null;\n source: string;\n project_id: string | null;\n};\n\ntype ChecklistRow = {\n item_id: string;\n goal_id: string;\n text: string;\n status: string;\n added_by: string;\n added_at: number;\n completed_at: number | null;\n evidence_summary: string | null;\n sort_order: number;\n};\n\ntype GoalRunRow = {\n run_id: string;\n goal_id: string;\n session_key: string;\n source: string;\n status: string;\n started_at: number;\n finished_at: number | null;\n verdict: string | null;\n reason: string | null;\n next_action: string | null;\n assistant_preview: string | null;\n checklist_done: number | null;\n checklist_total: number | null;\n confidence: number | null;\n missing_evidence_json: string | null;\n user_question: string | null;\n completed_checklist_item_ids_json: string | null;\n};\n\ntype EventRow = {\n event_id: string;\n goal_id: string;\n run_id: string | null;\n kind: string;\n message: string;\n data_json: string | null;\n created_at: number;\n};\n\ntype EvidenceRow = {\n evidence_id: string;\n goal_id: string;\n run_id: string | null;\n kind: GoalEvidence['kind'];\n title: string;\n summary: string | null;\n uri: string | null;\n data_json: string | null;\n created_at: number;\n};\n\ntype GoalContextRow = {\n goal_id: string;\n text: string;\n attachments_json: string;\n created_at: number;\n updated_at: number;\n};\n\ntype GoalContractRow = {\n goal_id: string;\n version: number;\n objective: string;\n scope_boundary: string | null;\n evidence_plan_json: string;\n created_at: number;\n updated_at: number;\n};\n\ntype GoalEvidenceRequirementRow = {\n requirement_id: string;\n goal_id: string;\n text: string;\n status: GoalEvidenceRequirementStatus;\n review_reason: string | null;\n review_confidence: number | null;\n reviewed_by: GoalEvidenceReviewSource | null;\n reviewed_at: number | null;\n requires_human_approval: number;\n created_at: number;\n updated_at: number;\n sort_order: number;\n};\n\nfunction goalFromRow(row: GoalRow): Goal {\n return {\n id: row.goal_id,\n title: row.title,\n description: row.description ?? undefined,\n status: row.status as GoalStatus,\n agentId: row.agent_id,\n priority: row.priority as GoalPriority,\n deadlineAt: row.deadline_at ?? undefined,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n completedAt: row.completed_at ?? undefined,\n archivedAt: row.archived_at ?? undefined,\n activeSessionKey: row.active_session_key ?? undefined,\n currentRunId: row.current_run_id ?? undefined,\n nextAction: row.next_action ?? undefined,\n blockedReason: row.blocked_reason ?? undefined,\n judgeModelRef: row.judge_model_ref ?? undefined,\n maxTurns: row.max_turns,\n turnsUsed: row.turns_used,\n uiLocale: row.ui_locale === 'en' || row.ui_locale === 'zh' ? row.ui_locale : undefined,\n source: row.source as GoalSource,\n projectId: row.project_id ?? undefined,\n };\n}\n\nfunction checklistFromRow(row: ChecklistRow): GoalChecklistItem {\n return {\n id: row.item_id,\n goalId: row.goal_id,\n text: row.text,\n status: row.status as GoalChecklistStatus,\n addedBy: row.added_by as GoalChecklistAddedBy,\n addedAt: row.added_at,\n completedAt: row.completed_at ?? undefined,\n evidenceSummary: row.evidence_summary ?? undefined,\n sortOrder: row.sort_order,\n };\n}\n\nfunction runFromRow(row: GoalRunRow): GoalRun {\n return {\n id: row.run_id,\n goalId: row.goal_id,\n sessionKey: row.session_key,\n source: row.source as GoalSource,\n status: row.status as GoalRunStatus,\n startedAt: row.started_at,\n finishedAt: row.finished_at ?? undefined,\n verdict: row.verdict ? (row.verdict as GoalRunVerdict) : undefined,\n reason: row.reason ?? undefined,\n nextAction: row.next_action ?? undefined,\n assistantPreview: row.assistant_preview ?? undefined,\n checklistProgress:\n row.checklist_done != null && row.checklist_total != null\n ? { done: row.checklist_done, total: row.checklist_total }\n : undefined,\n confidence: row.confidence ?? undefined,\n missingEvidence: parseJsonStringArray(row.missing_evidence_json),\n userQuestion: row.user_question ?? undefined,\n completedChecklistItemIds: parseJsonStringArray(row.completed_checklist_item_ids_json),\n };\n}\n\nfunction parseJsonField(raw: string | null): unknown {\n if (!raw) return undefined;\n try {\n return JSON.parse(raw) as unknown;\n } catch {\n return undefined;\n }\n}\n\nfunction parseJsonStringArray(raw: string | null): string[] | undefined {\n const value = parseJsonField(raw);\n if (!Array.isArray(value)) return undefined;\n const rows = value.filter((item): item is string => typeof item === 'string' && item.trim().length > 0);\n return rows.length ? rows : undefined;\n}\n\nfunction parseGoalContextAttachments(raw: string): GoalContextAttachment[] {\n const parsed = parseJsonField(raw);\n if (!Array.isArray(parsed)) return [];\n return parsed.filter((item): item is GoalContextAttachment => {\n if (!item || typeof item !== 'object') return false;\n const ref = item as Partial<GoalContextAttachment>;\n return (\n typeof ref.id === 'string' &&\n (ref.bucket === 'inbound' || ref.bucket === 'tts' || ref.bucket === 'outbound' || ref.bucket === 'work-item') &&\n typeof ref.type === 'string' &&\n typeof ref.mimeType === 'string' &&\n typeof ref.name === 'string' &&\n typeof ref.size === 'number' &&\n typeof ref.uri === 'string' &&\n typeof ref.path === 'string'\n );\n });\n}\n\nfunction goalContextFromRow(row: GoalContextRow): GoalContextMessage {\n return {\n goalId: row.goal_id,\n text: row.text,\n attachments: parseGoalContextAttachments(row.attachments_json),\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction goalContractFromRow(row: GoalContractRow): GoalContract {\n return {\n goalId: row.goal_id,\n version: row.version,\n objective: row.objective,\n scopeBoundary: row.scope_boundary ?? undefined,\n evidencePlan: parseJsonStringArray(row.evidence_plan_json) ?? [],\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction normalizeStringList(items: string[] | undefined, limit = 20): string[] {\n if (!items) return [];\n const seen = new Set<string>();\n const result: string[] = [];\n for (const item of items) {\n const text = item.trim();\n const key = text.toLocaleLowerCase();\n if (!text || seen.has(key)) continue;\n seen.add(key);\n result.push(text);\n if (result.length >= limit) break;\n }\n return result;\n}\n\nfunction normalizeContract(\n input: GoalContractInput | undefined,\n goalId: string,\n fallbackObjective: string,\n now: number,\n version = 1,\n createdAt = now,\n): GoalContract | undefined {\n if (!input) return undefined;\n return {\n goalId,\n version,\n objective: input.objective?.trim() || fallbackObjective,\n scopeBoundary: input.scopeBoundary?.trim() || undefined,\n evidencePlan: normalizeStringList(input.evidencePlan),\n createdAt,\n updatedAt: now,\n };\n}\n\nfunction insertGoalContract(db: ReturnType<typeof getSqliteDatabase>, contract: GoalContract): void {\n db.prepare(\n `INSERT INTO goal_contracts (\n goal_id, version, objective, scope_boundary, evidence_plan_json, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?)`,\n ).run(\n contract.goalId,\n contract.version,\n contract.objective,\n contract.scopeBoundary ?? null,\n JSON.stringify(contract.evidencePlan),\n contract.createdAt,\n contract.updatedAt,\n );\n}\n\nfunction eventFromRow(row: EventRow): GoalEvent {\n return {\n id: row.event_id,\n goalId: row.goal_id,\n runId: row.run_id ?? undefined,\n kind: row.kind,\n message: row.message,\n data: parseJsonField(row.data_json),\n createdAt: row.created_at,\n };\n}\n\nfunction evidenceFromRow(row: EvidenceRow): GoalEvidence {\n return {\n id: row.evidence_id,\n goalId: row.goal_id,\n runId: row.run_id ?? undefined,\n kind: row.kind,\n title: row.title,\n summary: row.summary ?? undefined,\n uri: row.uri ?? undefined,\n data: parseJsonField(row.data_json),\n createdAt: row.created_at,\n };\n}\n\nfunction evidenceRequirementFromRow(row: GoalEvidenceRequirementRow, evidenceIds: string[] = []): GoalEvidenceRequirement {\n return {\n id: row.requirement_id,\n goalId: row.goal_id,\n text: row.text,\n status: row.status,\n evidenceIds,\n reviewReason: row.review_reason ?? undefined,\n reviewConfidence: row.review_confidence ?? undefined,\n reviewedBy: row.reviewed_by ?? undefined,\n reviewedAt: row.reviewed_at ?? undefined,\n requiresHumanApproval: Boolean(row.requires_human_approval),\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n sortOrder: row.sort_order,\n };\n}\n\nfunction syncEvidenceRequirements(\n db: ReturnType<typeof getSqliteDatabase>,\n goalId: string,\n evidencePlan: string[],\n now: number,\n): void {\n const existing = db\n .prepare(`SELECT * FROM goal_evidence_requirements WHERE goal_id = ?`)\n .all(goalId) as GoalEvidenceRequirementRow[];\n const byText = new Map(existing.map((item) => [item.text.toLocaleLowerCase(), item]));\n const desired = new Set(evidencePlan.map((text) => text.toLocaleLowerCase()));\n for (const item of existing) {\n if (!desired.has(item.text.toLocaleLowerCase())) {\n db.prepare(`DELETE FROM goal_evidence_requirements WHERE requirement_id = ?`).run(item.requirement_id);\n }\n }\n for (const [index, text] of evidencePlan.entries()) {\n const current = byText.get(text.toLocaleLowerCase());\n if (current) {\n db.prepare(\n `UPDATE goal_evidence_requirements\n SET text = ?, sort_order = ?, updated_at = ?\n WHERE requirement_id = ?`,\n ).run(text, index + 1, now, current.requirement_id);\n } else {\n db.prepare(\n `INSERT INTO goal_evidence_requirements (\n requirement_id, goal_id, text, status, requires_human_approval, created_at, updated_at, sort_order\n ) VALUES (?, ?, ?, 'pending', 1, ?, ?, ?)`,\n ).run(randomUUID(), goalId, text, now, now, index + 1);\n }\n }\n}\n\nfunction clampLimit(n: number | undefined, fallback: number): number {\n return Math.min(500, Math.max(1, Math.floor(n ?? fallback)));\n}\n\nfunction insertGoalEvent(db: ReturnType<typeof getSqliteDatabase>, input: {\n goalId: string;\n runId?: string;\n kind: string;\n message: string;\n data?: unknown;\n createdAt?: number;\n}): GoalEvent {\n const event: GoalEvent = {\n id: randomUUID(),\n goalId: input.goalId,\n runId: input.runId,\n kind: input.kind,\n message: input.message,\n data: input.data,\n createdAt: input.createdAt ?? Date.now(),\n };\n db.prepare(\n `INSERT INTO goal_events (event_id, goal_id, run_id, kind, message, data_json, created_at)\n VALUES (?, ?, ?, ?, ?, ?, ?)`,\n ).run(\n event.id,\n event.goalId,\n event.runId ?? null,\n event.kind,\n event.message,\n event.data === undefined ? null : JSON.stringify(event.data),\n event.createdAt,\n );\n return event;\n}\n\nexport class GoalStore {\n create(input: CreateGoalInput): Goal {\n const now = Date.now();\n const goal: Goal = {\n id: randomUUID(),\n title: input.title.trim(),\n description: input.description?.trim() || undefined,\n status: 'active',\n agentId: input.agentId,\n priority: input.priority ?? 'normal',\n deadlineAt: input.deadlineAt,\n createdAt: now,\n updatedAt: now,\n activeSessionKey: input.sessionKey,\n judgeModelRef: input.judgeModelRef?.trim() || undefined,\n maxTurns: Math.max(1, Math.min(500, Math.floor(input.maxTurns))),\n turnsUsed: 0,\n uiLocale: input.uiLocale,\n source: input.source ?? 'chat',\n projectId: input.projectId?.trim() || undefined,\n };\n const contract = normalizeContract(input.contract, goal.id, goal.title, now);\n const criteria = normalizeStringList(input.contract?.criteria);\n\n runSqliteWriteTransaction((db) => {\n db.prepare(\n `INSERT INTO goals (\n goal_id, title, description, status, agent_id, priority, deadline_at,\n created_at, updated_at, active_session_key, judge_model_ref,\n max_turns, turns_used, ui_locale, source, project_id\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n ).run(\n goal.id,\n goal.title,\n goal.description ?? null,\n goal.status,\n goal.agentId,\n goal.priority,\n goal.deadlineAt ?? null,\n goal.createdAt,\n goal.updatedAt,\n goal.activeSessionKey ?? null,\n goal.judgeModelRef ?? null,\n goal.maxTurns,\n goal.turnsUsed,\n goal.uiLocale ?? null,\n goal.source,\n goal.projectId ?? null,\n );\n if (goal.activeSessionKey) {\n db.prepare(\n `INSERT OR REPLACE INTO goal_session_links (goal_id, session_key, linked_at)\n VALUES (?, ?, ?)`,\n ).run(goal.id, goal.activeSessionKey, now);\n }\n if (contract) {\n insertGoalContract(db, contract);\n syncEvidenceRequirements(db, goal.id, contract.evidencePlan, now);\n for (const [index, text] of criteria.entries()) {\n db.prepare(\n `INSERT INTO goal_checklist_items (\n item_id, goal_id, text, status, added_by, added_at, sort_order\n ) VALUES (?, ?, ?, 'pending', 'user', ?, ?)`,\n ).run(randomUUID(), goal.id, text, now, index + 1);\n }\n insertGoalEvent(db, {\n goalId: goal.id,\n kind: 'contract_created',\n message: contract.objective,\n data: { version: contract.version, criteriaCount: criteria.length, evidenceCount: contract.evidencePlan.length },\n createdAt: now,\n });\n }\n insertGoalEvent(db, { goalId: goal.id, kind: 'created', message: 'Goal created', createdAt: now });\n });\n\n return goal;\n }\n\n get(goalId: string): Goal | null {\n const row = getSqliteDatabase()\n .prepare(`SELECT * FROM goals WHERE goal_id = ?`)\n .get(goalId) as GoalRow | undefined;\n return row ? goalFromRow(row) : null;\n }\n\n setContextMessage(input: {\n goalId: string;\n text: string;\n attachments?: GoalContextAttachment[];\n }): GoalContextMessage {\n return runSqliteWriteTransaction((db) => {\n const now = Date.now();\n const existing = db\n .prepare(`SELECT created_at FROM goal_context_messages WHERE goal_id = ?`)\n .get(input.goalId) as { created_at: number } | undefined;\n db.prepare(\n `INSERT INTO goal_context_messages (goal_id, text, attachments_json, created_at, updated_at)\n VALUES (?, ?, ?, ?, ?)\n ON CONFLICT(goal_id) DO UPDATE SET\n text = excluded.text,\n attachments_json = excluded.attachments_json,\n updated_at = excluded.updated_at`,\n ).run(\n input.goalId,\n input.text.trim(),\n JSON.stringify(input.attachments ?? []),\n existing?.created_at ?? now,\n now,\n );\n insertGoalEvent(db, {\n goalId: input.goalId,\n kind: 'context_updated',\n message: input.text.trim() || `${input.attachments?.length ?? 0} attachment(s)`,\n data: { attachmentCount: input.attachments?.length ?? 0 },\n createdAt: now,\n });\n const row = db\n .prepare(`SELECT * FROM goal_context_messages WHERE goal_id = ?`)\n .get(input.goalId) as GoalContextRow;\n return goalContextFromRow(row);\n });\n }\n\n getContextMessage(goalId: string): GoalContextMessage | null {\n const row = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_context_messages WHERE goal_id = ?`)\n .get(goalId) as GoalContextRow | undefined;\n return row ? goalContextFromRow(row) : null;\n }\n\n getContract(goalId: string): GoalContract | null {\n const row = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_contracts WHERE goal_id = ?`)\n .get(goalId) as GoalContractRow | undefined;\n return row ? goalContractFromRow(row) : null;\n }\n\n setContract(goalId: string, input: GoalContractInput): GoalContract | null {\n const goal = this.get(goalId);\n if (!goal) return null;\n return runSqliteWriteTransaction((db) => {\n const existing = db\n .prepare(`SELECT * FROM goal_contracts WHERE goal_id = ?`)\n .get(goalId) as GoalContractRow | undefined;\n const now = Date.now();\n const contract = normalizeContract(\n input,\n goalId,\n goal.title,\n now,\n (existing?.version ?? 0) + 1,\n existing?.created_at ?? now,\n );\n if (!contract) return null;\n db.prepare(\n `INSERT INTO goal_contracts (\n goal_id, version, objective, scope_boundary, evidence_plan_json, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?)\n ON CONFLICT(goal_id) DO UPDATE SET\n version = excluded.version,\n objective = excluded.objective,\n scope_boundary = excluded.scope_boundary,\n evidence_plan_json = excluded.evidence_plan_json,\n updated_at = excluded.updated_at`,\n ).run(\n contract.goalId,\n contract.version,\n contract.objective,\n contract.scopeBoundary ?? null,\n JSON.stringify(contract.evidencePlan),\n contract.createdAt,\n contract.updatedAt,\n );\n syncEvidenceRequirements(db, goalId, contract.evidencePlan, now);\n insertGoalEvent(db, {\n goalId,\n kind: 'contract_updated',\n message: contract.objective,\n data: { version: contract.version, evidenceCount: contract.evidencePlan.length },\n createdAt: now,\n });\n return contract;\n });\n }\n\n getActiveForSession(sessionKey: string): Goal | null {\n const row = getSqliteDatabase()\n .prepare(\n `SELECT * FROM goals\n WHERE active_session_key = ?\n AND status IN ('active', 'paused', 'blocked', 'needs_input', 'done')\n ORDER BY updated_at DESC\n LIMIT 1`,\n )\n .get(sessionKey) as GoalRow | undefined;\n return row ? goalFromRow(row) : null;\n }\n\n list(query: GoalListQuery = {}): Goal[] {\n const conditions: string[] = [];\n const params: Array<string | number> = [];\n if (query.status) {\n const statuses = Array.isArray(query.status) ? query.status : [query.status];\n conditions.push(`status IN (${statuses.map(() => '?').join(', ')})`);\n params.push(...statuses);\n }\n if (query.agentId) {\n conditions.push(`agent_id = ?`);\n params.push(query.agentId);\n }\n if (query.sessionKey) {\n conditions.push(`goal_id IN (SELECT goal_id FROM goal_session_links WHERE session_key = ?)`);\n params.push(query.sessionKey);\n }\n if (query.projectId) {\n conditions.push(`project_id = ?`);\n params.push(query.projectId);\n }\n const where = conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';\n const limit = clampLimit(query.limit, 50);\n const offset = Math.max(0, Math.floor(query.offset ?? 0));\n const rows = getSqliteDatabase()\n .prepare(`SELECT * FROM goals ${where} ORDER BY updated_at DESC LIMIT ? OFFSET ?`)\n .all(...params, limit, offset) as GoalRow[];\n return rows.map(goalFromRow);\n }\n\n update(goalId: string, patch: Partial<Pick<\n Goal,\n | 'title'\n | 'description'\n | 'status'\n | 'priority'\n | 'deadlineAt'\n | 'completedAt'\n | 'archivedAt'\n | 'activeSessionKey'\n | 'currentRunId'\n | 'nextAction'\n | 'blockedReason'\n | 'judgeModelRef'\n | 'maxTurns'\n | 'turnsUsed'\n | 'uiLocale'\n | 'projectId'\n >>): Goal | null {\n const before = this.get(goalId);\n if (!before) return null;\n const next = { ...before, ...patch, updatedAt: Date.now() };\n runSqliteWriteTransaction((db) => {\n db.prepare(\n `UPDATE goals SET\n title = ?, description = ?, status = ?, priority = ?, deadline_at = ?,\n updated_at = ?, completed_at = ?, archived_at = ?, active_session_key = ?,\n current_run_id = ?, next_action = ?, blocked_reason = ?, judge_model_ref = ?,\n max_turns = ?, turns_used = ?, ui_locale = ?, project_id = ?\n WHERE goal_id = ?`,\n ).run(\n next.title,\n next.description ?? null,\n next.status,\n next.priority,\n next.deadlineAt ?? null,\n next.updatedAt,\n next.completedAt ?? null,\n next.archivedAt ?? null,\n next.activeSessionKey ?? null,\n next.currentRunId ?? null,\n next.nextAction ?? null,\n next.blockedReason ?? null,\n next.judgeModelRef ?? null,\n next.maxTurns,\n next.turnsUsed,\n next.uiLocale ?? null,\n next.projectId ?? null,\n goalId,\n );\n if (next.activeSessionKey) {\n db.prepare(\n `INSERT OR REPLACE INTO goal_session_links (goal_id, session_key, linked_at)\n VALUES (?, ?, ?)`,\n ).run(goalId, next.activeSessionKey, next.updatedAt);\n }\n });\n return this.get(goalId);\n }\n\n listChecklist(goalId: string): GoalChecklistItem[] {\n const rows = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_checklist_items WHERE goal_id = ? ORDER BY sort_order ASC, added_at ASC`)\n .all(goalId) as ChecklistRow[];\n return rows.map(checklistFromRow);\n }\n\n addChecklistItem(input: {\n goalId: string;\n text: string;\n addedBy: GoalChecklistAddedBy;\n status?: GoalChecklistStatus;\n }): GoalChecklistItem {\n return runSqliteWriteTransaction((db) => {\n const maxRow = db\n .prepare(`SELECT COALESCE(MAX(sort_order), 0) AS max_sort FROM goal_checklist_items WHERE goal_id = ?`)\n .get(input.goalId) as { max_sort: number };\n const now = Date.now();\n const item: GoalChecklistItem = {\n id: randomUUID(),\n goalId: input.goalId,\n text: input.text.trim(),\n status: input.status ?? 'pending',\n addedBy: input.addedBy,\n addedAt: now,\n sortOrder: maxRow.max_sort + 1,\n };\n db.prepare(\n `INSERT INTO goal_checklist_items (\n item_id, goal_id, text, status, added_by, added_at, sort_order\n ) VALUES (?, ?, ?, ?, ?, ?, ?)`,\n ).run(item.id, item.goalId, item.text, item.status, item.addedBy, item.addedAt, item.sortOrder);\n insertGoalEvent(db, {\n goalId: input.goalId,\n kind: 'checklist_added',\n message: item.text,\n data: { itemId: item.id, addedBy: item.addedBy },\n createdAt: now,\n });\n return item;\n });\n }\n\n updateChecklistItem(\n itemId: string,\n patch: Partial<Pick<GoalChecklistItem, 'text' | 'status' | 'evidenceSummary'>>,\n ): GoalChecklistItem | null {\n return runSqliteWriteTransaction((db) => {\n const row = db\n .prepare(`SELECT * FROM goal_checklist_items WHERE item_id = ?`)\n .get(itemId) as ChecklistRow | undefined;\n if (!row) return null;\n const before = checklistFromRow(row);\n const status = patch.status ?? before.status;\n const completedAt =\n status === 'completed' || status === 'impossible'\n ? (before.completedAt ?? Date.now())\n : null;\n db.prepare(\n `UPDATE goal_checklist_items SET text = ?, status = ?, completed_at = ?, evidence_summary = ?\n WHERE item_id = ?`,\n ).run(\n patch.text?.trim() || before.text,\n status,\n completedAt,\n patch.evidenceSummary ?? before.evidenceSummary ?? null,\n itemId,\n );\n insertGoalEvent(db, {\n goalId: before.goalId,\n kind: 'checklist_updated',\n message: patch.text?.trim() || before.text,\n data: { itemId, status },\n });\n const next = db\n .prepare(`SELECT * FROM goal_checklist_items WHERE item_id = ?`)\n .get(itemId) as ChecklistRow;\n return checklistFromRow(next);\n });\n }\n\n removeChecklistItem(itemId: string): boolean {\n return runSqliteWriteTransaction((db) => {\n const row = db\n .prepare(`SELECT goal_id, text FROM goal_checklist_items WHERE item_id = ?`)\n .get(itemId) as { goal_id: string; text: string } | undefined;\n if (!row) return false;\n db.prepare(`DELETE FROM goal_checklist_items WHERE item_id = ?`).run(itemId);\n insertGoalEvent(db, {\n goalId: row.goal_id,\n kind: 'checklist_removed',\n message: row.text,\n data: { itemId },\n });\n return true;\n });\n }\n\n clearChecklist(goalId: string): void {\n runSqliteWriteTransaction((db) => {\n db.prepare(`DELETE FROM goal_checklist_items WHERE goal_id = ?`).run(goalId);\n insertGoalEvent(db, { goalId, kind: 'checklist_cleared', message: 'Checklist cleared' });\n });\n }\n\n replaceChecklist(goalId: string, items: Array<{\n text: string;\n status: GoalChecklistStatus;\n addedBy: GoalChecklistAddedBy;\n addedAt?: number;\n completedAt?: number;\n evidenceSummary?: string;\n }>): GoalChecklistItem[] {\n return runSqliteWriteTransaction((db) => {\n db.prepare(`DELETE FROM goal_checklist_items WHERE goal_id = ?`).run(goalId);\n const now = Date.now();\n const next: GoalChecklistItem[] = [];\n for (let i = 0; i < items.length; i++) {\n const raw = items[i]!;\n const item: GoalChecklistItem = {\n id: randomUUID(),\n goalId,\n text: raw.text.trim(),\n status: raw.status,\n addedBy: raw.addedBy,\n addedAt: raw.addedAt ?? now,\n completedAt: raw.completedAt,\n evidenceSummary: raw.evidenceSummary,\n sortOrder: i + 1,\n };\n if (!item.text) continue;\n db.prepare(\n `INSERT INTO goal_checklist_items (\n item_id, goal_id, text, status, added_by, added_at, completed_at, evidence_summary, sort_order\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n ).run(\n item.id,\n item.goalId,\n item.text,\n item.status,\n item.addedBy,\n item.addedAt,\n item.completedAt ?? null,\n item.evidenceSummary ?? null,\n item.sortOrder,\n );\n next.push(item);\n }\n insertGoalEvent(db, {\n goalId,\n kind: 'checklist_replaced',\n message: `Checklist replaced (${next.length} items)`,\n });\n return next;\n });\n }\n\n appendRun(run: Omit<GoalRun, 'id' | 'startedAt'> & { id?: string; startedAt?: number }): GoalRun {\n const record: GoalRun = {\n id: run.id ?? randomUUID(),\n goalId: run.goalId,\n sessionKey: run.sessionKey,\n source: run.source,\n status: run.status,\n startedAt: run.startedAt ?? Date.now(),\n finishedAt: run.finishedAt,\n verdict: run.verdict,\n reason: run.reason,\n nextAction: run.nextAction,\n assistantPreview: run.assistantPreview,\n checklistProgress: run.checklistProgress,\n };\n runSqliteWriteTransaction((db) => {\n db.prepare(\n `INSERT INTO goal_runs (\n run_id, goal_id, session_key, source, status, started_at, finished_at,\n verdict, reason, next_action, assistant_preview, checklist_done, checklist_total,\n confidence, missing_evidence_json, user_question, completed_checklist_item_ids_json\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n ).run(\n record.id,\n record.goalId,\n record.sessionKey,\n record.source,\n record.status,\n record.startedAt,\n record.finishedAt ?? null,\n record.verdict ?? null,\n record.reason ?? null,\n record.nextAction ?? null,\n record.assistantPreview ?? null,\n record.checklistProgress?.done ?? null,\n record.checklistProgress?.total ?? null,\n record.confidence ?? null,\n record.missingEvidence ? JSON.stringify(record.missingEvidence) : null,\n record.userQuestion ?? null,\n record.completedChecklistItemIds ? JSON.stringify(record.completedChecklistItemIds) : null,\n );\n db.prepare(`UPDATE goals SET current_run_id = ?, updated_at = ? WHERE goal_id = ?`).run(\n record.id,\n record.finishedAt ?? record.startedAt,\n record.goalId,\n );\n insertGoalEvent(db, {\n goalId: record.goalId,\n runId: record.id,\n kind: 'run_recorded',\n message: record.reason ?? record.status,\n data: {\n verdict: record.verdict,\n status: record.status,\n confidence: record.confidence,\n missingEvidence: record.missingEvidence,\n userQuestion: record.userQuestion,\n completedChecklistItemIds: record.completedChecklistItemIds,\n },\n createdAt: record.finishedAt ?? record.startedAt,\n });\n });\n return record;\n }\n\n listRuns(goalId: string, limit?: number): GoalRun[] {\n const rows = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_runs WHERE goal_id = ? ORDER BY started_at DESC LIMIT ?`)\n .all(goalId, clampLimit(limit, 50)) as GoalRunRow[];\n return rows.map(runFromRow);\n }\n\n listRunsForSession(sessionKey: string, limit?: number): GoalRun[] {\n const rows = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_runs WHERE session_key = ? ORDER BY started_at DESC LIMIT ?`)\n .all(sessionKey, clampLimit(limit, 50)) as GoalRunRow[];\n return rows.map(runFromRow);\n }\n\n listEvents(goalId: string, limit?: number): GoalEvent[] {\n const rows = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_events WHERE goal_id = ? ORDER BY created_at DESC LIMIT ?`)\n .all(goalId, clampLimit(limit, 100)) as EventRow[];\n return rows.map(eventFromRow);\n }\n\n addEvidence(input: Omit<GoalEvidence, 'id' | 'createdAt'> & { id?: string; createdAt?: number }): GoalEvidence {\n const evidence: GoalEvidence = {\n id: input.id ?? randomUUID(),\n goalId: input.goalId,\n runId: input.runId,\n kind: input.kind,\n title: input.title,\n summary: input.summary,\n uri: input.uri,\n data: input.data,\n createdAt: input.createdAt ?? Date.now(),\n };\n runSqliteWriteTransaction((db) => {\n db.prepare(\n `INSERT INTO goal_evidence (\n evidence_id, goal_id, run_id, kind, title, summary, uri, data_json, created_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n ).run(\n evidence.id,\n evidence.goalId,\n evidence.runId ?? null,\n evidence.kind,\n evidence.title,\n evidence.summary ?? null,\n evidence.uri ?? null,\n evidence.data === undefined ? null : JSON.stringify(evidence.data),\n evidence.createdAt,\n );\n insertGoalEvent(db, {\n goalId: evidence.goalId,\n runId: evidence.runId,\n kind: 'evidence_added',\n message: evidence.title,\n data: { evidenceId: evidence.id, kind: evidence.kind },\n createdAt: evidence.createdAt,\n });\n });\n return evidence;\n }\n\n listEvidence(goalId: string, limit?: number): GoalEvidence[] {\n const rows = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_evidence WHERE goal_id = ? ORDER BY created_at DESC LIMIT ?`)\n .all(goalId, clampLimit(limit, 100)) as EvidenceRow[];\n const db = getSqliteDatabase();\n return rows.map((row) => ({\n ...evidenceFromRow(row),\n requirementIds: (db.prepare(\n `SELECT requirement_id FROM goal_evidence_requirement_links WHERE evidence_id = ? ORDER BY requirement_id`,\n ).all(row.evidence_id) as Array<{ requirement_id: string }>).map((item) => item.requirement_id),\n }));\n }\n\n listEvidenceRequirements(goalId: string): GoalEvidenceRequirement[] {\n const db = getSqliteDatabase();\n const rows = db\n .prepare(`SELECT * FROM goal_evidence_requirements WHERE goal_id = ? ORDER BY sort_order ASC`)\n .all(goalId) as GoalEvidenceRequirementRow[];\n return rows.map((row) => evidenceRequirementFromRow(\n row,\n (db.prepare(\n `SELECT evidence_id FROM goal_evidence_requirement_links WHERE requirement_id = ? ORDER BY created_at ASC`,\n ).all(row.requirement_id) as Array<{ evidence_id: string }>).map((item) => item.evidence_id),\n ));\n }\n\n linkEvidenceRequirement(input: {\n goalId: string;\n requirementId: string;\n evidenceId: string;\n linkedBy: 'user' | 'agent' | 'system';\n }): GoalEvidenceRequirement | null {\n return runSqliteWriteTransaction((db) => {\n const requirement = db.prepare(\n `SELECT * FROM goal_evidence_requirements WHERE requirement_id = ? AND goal_id = ?`,\n ).get(input.requirementId, input.goalId) as GoalEvidenceRequirementRow | undefined;\n const evidence = db.prepare(\n `SELECT evidence_id FROM goal_evidence WHERE evidence_id = ? AND goal_id = ?`,\n ).get(input.evidenceId, input.goalId) as { evidence_id: string } | undefined;\n if (!requirement || !evidence) return null;\n const now = Date.now();\n db.prepare(\n `INSERT OR IGNORE INTO goal_evidence_requirement_links (requirement_id, evidence_id, linked_by, created_at)\n VALUES (?, ?, ?, ?)`,\n ).run(input.requirementId, input.evidenceId, input.linkedBy, now);\n db.prepare(\n `UPDATE goal_evidence_requirements\n SET status = CASE WHEN status = 'rejected' THEN 'pending' ELSE status END,\n updated_at = ?\n WHERE requirement_id = ?`,\n ).run(now, input.requirementId);\n insertGoalEvent(db, {\n goalId: input.goalId,\n kind: 'evidence_requirement_linked',\n message: requirement.text,\n data: { requirementId: input.requirementId, evidenceId: input.evidenceId, linkedBy: input.linkedBy },\n createdAt: now,\n });\n const ids = (db.prepare(\n `SELECT evidence_id FROM goal_evidence_requirement_links WHERE requirement_id = ? ORDER BY created_at ASC`,\n ).all(input.requirementId) as Array<{ evidence_id: string }>).map((item) => item.evidence_id);\n const next = db.prepare(`SELECT * FROM goal_evidence_requirements WHERE requirement_id = ?`)\n .get(input.requirementId) as GoalEvidenceRequirementRow;\n return evidenceRequirementFromRow(next, ids);\n });\n }\n\n reviewEvidenceRequirement(input: {\n goalId: string;\n requirementId: string;\n status: GoalEvidenceRequirementStatus;\n reason: string;\n confidence?: number;\n reviewedBy: GoalEvidenceReviewSource;\n }): GoalEvidenceRequirement | null {\n return runSqliteWriteTransaction((db) => {\n const current = db.prepare(\n `SELECT * FROM goal_evidence_requirements WHERE requirement_id = ? AND goal_id = ?`,\n ).get(input.requirementId, input.goalId) as GoalEvidenceRequirementRow | undefined;\n if (!current) return null;\n const now = Date.now();\n db.prepare(\n `UPDATE goal_evidence_requirements\n SET status = ?, review_reason = ?, review_confidence = ?, reviewed_by = ?, reviewed_at = ?, updated_at = ?\n WHERE requirement_id = ?`,\n ).run(\n input.status,\n input.reason.trim(),\n input.confidence ?? null,\n input.reviewedBy,\n now,\n now,\n input.requirementId,\n );\n insertGoalEvent(db, {\n goalId: input.goalId,\n kind: input.reviewedBy === 'user' ? 'evidence_requirement_approved' : 'evidence_requirement_reviewed',\n message: current.text,\n data: { requirementId: input.requirementId, status: input.status, reason: input.reason.trim(), confidence: input.confidence },\n createdAt: now,\n });\n const ids = (db.prepare(\n `SELECT evidence_id FROM goal_evidence_requirement_links WHERE requirement_id = ? ORDER BY created_at ASC`,\n ).all(input.requirementId) as Array<{ evidence_id: string }>).map((item) => item.evidence_id);\n const next = db.prepare(`SELECT * FROM goal_evidence_requirements WHERE requirement_id = ?`)\n .get(input.requirementId) as GoalEvidenceRequirementRow;\n return evidenceRequirementFromRow(next, ids);\n });\n }\n}\n"],"mappings":";;;AA0IA,SAAS,YAAY,KAAoB;AACvC,QAAO;EACL,IAAI,IAAI;EACR,OAAO,IAAI;EACX,aAAa,IAAI,eAAe,KAAA;EAChC,QAAQ,IAAI;EACZ,SAAS,IAAI;EACb,UAAU,IAAI;EACd,YAAY,IAAI,eAAe,KAAA;EAC/B,WAAW,IAAI;EACf,WAAW,IAAI;EACf,aAAa,IAAI,gBAAgB,KAAA;EACjC,YAAY,IAAI,eAAe,KAAA;EAC/B,kBAAkB,IAAI,sBAAsB,KAAA;EAC5C,cAAc,IAAI,kBAAkB,KAAA;EACpC,YAAY,IAAI,eAAe,KAAA;EAC/B,eAAe,IAAI,kBAAkB,KAAA;EACrC,eAAe,IAAI,mBAAmB,KAAA;EACtC,UAAU,IAAI;EACd,WAAW,IAAI;EACf,UAAU,IAAI,cAAc,QAAQ,IAAI,cAAc,OAAO,IAAI,YAAY,KAAA;EAC7E,QAAQ,IAAI;EACZ,WAAW,IAAI,cAAc,KAAA;EAC9B;;AAGH,SAAS,iBAAiB,KAAsC;AAC9D,QAAO;EACL,IAAI,IAAI;EACR,QAAQ,IAAI;EACZ,MAAM,IAAI;EACV,QAAQ,IAAI;EACZ,SAAS,IAAI;EACb,SAAS,IAAI;EACb,aAAa,IAAI,gBAAgB,KAAA;EACjC,iBAAiB,IAAI,oBAAoB,KAAA;EACzC,WAAW,IAAI;EAChB;;AAGH,SAAS,WAAW,KAA0B;AAC5C,QAAO;EACL,IAAI,IAAI;EACR,QAAQ,IAAI;EACZ,YAAY,IAAI;EA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BAAgB,IAAI;IAClB,QAAQ,MAAM;IACd,MAAM;IACN,SAAS,YAAY;IACrB,MAAM;KAAE,eAAe,MAAM;KAAe,YAAY,MAAM;KAAY,UAAU,MAAM;KAAU;IACpG,WAAW;IACZ,CAAC;GACF,MAAM,MAAO,GAAG,QACd,2GACD,CAAC,IAAI,MAAM,cAAc,CAAoC,KAAK,SAAS,KAAK,YAAY;AAG7F,UAAO,2BAFM,GAAG,QAAQ,oEAAoE,CACzF,IAAI,MAAM,cACyB,EAAE,IAAI;IAC5C;;CAGJ,0BAA0B,OAOS;AACjC,SAAO,2BAA2B,OAAO;GACvC,MAAM,UAAU,GAAG,QACjB,oFACD,CAAC,IAAI,MAAM,eAAe,MAAM,OAAO;AACxC,OAAI,CAAC,QAAS,QAAO;GACrB,MAAM,MAAM,KAAK,KAAK;AACtB,MAAG,QACD;;mCAGD,CAAC,IACA,MAAM,QACN,MAAM,OAAO,MAAM,EACnB,MAAM,cAAc,MACpB,MAAM,YACN,KACA,KACA,MAAM,cACP;AACD,mBAAgB,IAAI;IAClB,QAAQ,MAAM;IACd,MAAM,MAAM,eAAe,SAAS,kCAAkC;IACtE,SAAS,QAAQ;IACjB,MAAM;KAAE,eAAe,MAAM;KAAe,QAAQ,MAAM;KAAQ,QAAQ,MAAM,OAAO,MAAM;KAAE,YAAY,MAAM;KAAY;IAC7H,WAAW;IACZ,CAAC;GACF,MAAM,MAAO,GAAG,QACd,2GACD,CAAC,IAAI,MAAM,cAAc,CAAoC,KAAK,SAAS,KAAK,YAAY;AAG7F,UAAO,2BAFM,GAAG,QAAQ,oEAAoE,CACzF,IAAI,MAAM,cACyB,EAAE,IAAI;IAC5C"}
|
|
1
|
+
{"version":3,"file":"goal-store.js","names":[],"sources":["../../../src/goals/goal-store.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport { getSqliteDatabase, runSqliteWriteTransaction } from '../storage/sqlite/transaction.js';\nimport type {\n CreateGoalInput,\n Goal,\n GoalChecklistAddedBy,\n GoalChecklistItem,\n GoalChecklistStatus,\n GoalContextAttachment,\n GoalContextMessage,\n GoalContract,\n GoalContractInput,\n GoalEvent,\n GoalEvidence,\n GoalEvidenceRequirement,\n GoalEvidenceRequirementStatus,\n GoalEvidenceReviewSource,\n GoalListQuery,\n GoalOutcomeMetric,\n GoalPriority,\n GoalRun,\n GoalRunStatus,\n GoalRunVerdict,\n GoalSource,\n GoalStatus,\n} from './types.js';\n\ntype GoalRow = {\n goal_id: string;\n title: string;\n description: string | null;\n status: string;\n agent_id: string;\n priority: string;\n deadline_at: number | null;\n created_at: number;\n updated_at: number;\n completed_at: number | null;\n archived_at: number | null;\n active_session_key: string | null;\n current_run_id: string | null;\n next_action: string | null;\n blocked_reason: string | null;\n judge_model_ref: string | null;\n max_turns: number;\n turns_used: number;\n ui_locale: string | null;\n source: string;\n project_id: string | null;\n};\n\ntype ChecklistRow = {\n item_id: string;\n goal_id: string;\n text: string;\n status: string;\n added_by: string;\n added_at: number;\n completed_at: number | null;\n evidence_summary: string | null;\n sort_order: number;\n};\n\ntype GoalRunRow = {\n run_id: string;\n goal_id: string;\n session_key: string;\n source: string;\n status: string;\n started_at: number;\n finished_at: number | null;\n verdict: string | null;\n reason: string | null;\n next_action: string | null;\n assistant_preview: string | null;\n checklist_done: number | null;\n checklist_total: number | null;\n confidence: number | null;\n missing_evidence_json: string | null;\n user_question: string | null;\n completed_checklist_item_ids_json: string | null;\n};\n\ntype EventRow = {\n event_id: string;\n goal_id: string;\n run_id: string | null;\n kind: string;\n message: string;\n data_json: string | null;\n created_at: number;\n};\n\ntype EvidenceRow = {\n evidence_id: string;\n goal_id: string;\n run_id: string | null;\n kind: GoalEvidence['kind'];\n title: string;\n summary: string | null;\n uri: string | null;\n data_json: string | null;\n created_at: number;\n};\n\ntype GoalContextRow = {\n goal_id: string;\n text: string;\n attachments_json: string;\n created_at: number;\n updated_at: number;\n};\n\ntype GoalContractRow = {\n goal_id: string;\n version: number;\n objective: string;\n scope_boundary: string | null;\n evidence_plan_json: string;\n outcome_metric_json: string | null;\n created_at: number;\n updated_at: number;\n};\n\ntype GoalEvidenceRequirementRow = {\n requirement_id: string;\n goal_id: string;\n text: string;\n status: GoalEvidenceRequirementStatus;\n review_reason: string | null;\n review_confidence: number | null;\n reviewed_by: GoalEvidenceReviewSource | null;\n reviewed_at: number | null;\n requires_human_approval: number;\n created_at: number;\n updated_at: number;\n sort_order: number;\n};\n\nfunction goalFromRow(row: GoalRow): Goal {\n return {\n id: row.goal_id,\n title: row.title,\n description: row.description ?? undefined,\n status: row.status as GoalStatus,\n agentId: row.agent_id,\n priority: row.priority as GoalPriority,\n deadlineAt: row.deadline_at ?? undefined,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n completedAt: row.completed_at ?? undefined,\n archivedAt: row.archived_at ?? undefined,\n activeSessionKey: row.active_session_key ?? undefined,\n currentRunId: row.current_run_id ?? undefined,\n nextAction: row.next_action ?? undefined,\n blockedReason: row.blocked_reason ?? undefined,\n judgeModelRef: row.judge_model_ref ?? undefined,\n maxTurns: row.max_turns,\n turnsUsed: row.turns_used,\n uiLocale: row.ui_locale === 'en' || row.ui_locale === 'zh' ? row.ui_locale : undefined,\n source: row.source as GoalSource,\n projectId: row.project_id ?? undefined,\n };\n}\n\nfunction checklistFromRow(row: ChecklistRow): GoalChecklistItem {\n return {\n id: row.item_id,\n goalId: row.goal_id,\n text: row.text,\n status: row.status as GoalChecklistStatus,\n addedBy: row.added_by as GoalChecklistAddedBy,\n addedAt: row.added_at,\n completedAt: row.completed_at ?? undefined,\n evidenceSummary: row.evidence_summary ?? undefined,\n sortOrder: row.sort_order,\n };\n}\n\nfunction runFromRow(row: GoalRunRow): GoalRun {\n return {\n id: row.run_id,\n goalId: row.goal_id,\n sessionKey: row.session_key,\n source: row.source as GoalSource,\n status: row.status as GoalRunStatus,\n startedAt: row.started_at,\n finishedAt: row.finished_at ?? undefined,\n verdict: row.verdict ? (row.verdict as GoalRunVerdict) : undefined,\n reason: row.reason ?? undefined,\n nextAction: row.next_action ?? undefined,\n assistantPreview: row.assistant_preview ?? undefined,\n checklistProgress:\n row.checklist_done != null && row.checklist_total != null\n ? { done: row.checklist_done, total: row.checklist_total }\n : undefined,\n confidence: row.confidence ?? undefined,\n missingEvidence: parseJsonStringArray(row.missing_evidence_json),\n userQuestion: row.user_question ?? undefined,\n completedChecklistItemIds: parseJsonStringArray(row.completed_checklist_item_ids_json),\n };\n}\n\nfunction parseJsonField(raw: string | null): unknown {\n if (!raw) return undefined;\n try {\n return JSON.parse(raw) as unknown;\n } catch {\n return undefined;\n }\n}\n\nfunction parseJsonStringArray(raw: string | null): string[] | undefined {\n const value = parseJsonField(raw);\n if (!Array.isArray(value)) return undefined;\n const rows = value.filter((item): item is string => typeof item === 'string' && item.trim().length > 0);\n return rows.length ? rows : undefined;\n}\n\nfunction parseGoalContextAttachments(raw: string): GoalContextAttachment[] {\n const parsed = parseJsonField(raw);\n if (!Array.isArray(parsed)) return [];\n return parsed.filter((item): item is GoalContextAttachment => {\n if (!item || typeof item !== 'object') return false;\n const ref = item as Partial<GoalContextAttachment>;\n return (\n typeof ref.id === 'string' &&\n (ref.bucket === 'inbound' || ref.bucket === 'tts' || ref.bucket === 'outbound' || ref.bucket === 'work-item') &&\n typeof ref.type === 'string' &&\n typeof ref.mimeType === 'string' &&\n typeof ref.name === 'string' &&\n typeof ref.size === 'number' &&\n typeof ref.uri === 'string' &&\n typeof ref.path === 'string'\n );\n });\n}\n\nfunction goalContextFromRow(row: GoalContextRow): GoalContextMessage {\n return {\n goalId: row.goal_id,\n text: row.text,\n attachments: parseGoalContextAttachments(row.attachments_json),\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction goalContractFromRow(row: GoalContractRow): GoalContract {\n return {\n goalId: row.goal_id,\n version: row.version,\n objective: row.objective,\n scopeBoundary: row.scope_boundary ?? undefined,\n evidencePlan: parseJsonStringArray(row.evidence_plan_json) ?? [],\n outcomeMetric: parseGoalOutcomeMetric(row.outcome_metric_json),\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction parseGoalOutcomeMetric(raw: string | null): GoalOutcomeMetric | undefined {\n const value = parseJsonField(raw);\n if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined;\n const metric = value as Partial<GoalOutcomeMetric>;\n if (\n typeof metric.name !== 'string' || !metric.name.trim() ||\n typeof metric.baselineValue !== 'number' || !Number.isFinite(metric.baselineValue) ||\n typeof metric.targetValue !== 'number' || !Number.isFinite(metric.targetValue) ||\n (metric.direction !== 'increase' && metric.direction !== 'decrease')\n ) return undefined;\n return {\n name: metric.name.trim(),\n baselineValue: metric.baselineValue,\n targetValue: metric.targetValue,\n currentValue: typeof metric.currentValue === 'number' && Number.isFinite(metric.currentValue)\n ? metric.currentValue\n : undefined,\n unit: typeof metric.unit === 'string' && metric.unit.trim() ? metric.unit.trim() : undefined,\n direction: metric.direction,\n sourceUrl: typeof metric.sourceUrl === 'string' && metric.sourceUrl.trim() ? metric.sourceUrl.trim() : undefined,\n measuredAt: typeof metric.measuredAt === 'number' && Number.isFinite(metric.measuredAt)\n ? metric.measuredAt\n : undefined,\n };\n}\n\nfunction normalizeGoalOutcomeMetric(input: GoalContractInput['outcomeMetric']): GoalOutcomeMetric | undefined {\n if (!input) return undefined;\n return {\n name: input.name.trim(),\n baselineValue: input.baselineValue,\n targetValue: input.targetValue,\n currentValue: input.currentValue,\n unit: input.unit?.trim() || undefined,\n direction: input.direction ?? (input.targetValue >= input.baselineValue ? 'increase' : 'decrease'),\n sourceUrl: input.sourceUrl?.trim() || undefined,\n measuredAt: input.measuredAt,\n };\n}\n\nfunction normalizeStringList(items: string[] | undefined, limit = 20): string[] {\n if (!items) return [];\n const seen = new Set<string>();\n const result: string[] = [];\n for (const item of items) {\n const text = item.trim();\n const key = text.toLocaleLowerCase();\n if (!text || seen.has(key)) continue;\n seen.add(key);\n result.push(text);\n if (result.length >= limit) break;\n }\n return result;\n}\n\nfunction normalizeContract(\n input: GoalContractInput | undefined,\n goalId: string,\n fallbackObjective: string,\n now: number,\n version = 1,\n createdAt = now,\n): GoalContract | undefined {\n if (!input) return undefined;\n return {\n goalId,\n version,\n objective: input.objective?.trim() || fallbackObjective,\n scopeBoundary: input.scopeBoundary?.trim() || undefined,\n evidencePlan: normalizeStringList(input.evidencePlan),\n outcomeMetric: normalizeGoalOutcomeMetric(input.outcomeMetric),\n createdAt,\n updatedAt: now,\n };\n}\n\nfunction insertGoalContract(db: ReturnType<typeof getSqliteDatabase>, contract: GoalContract): void {\n db.prepare(\n `INSERT INTO goal_contracts (\n goal_id, version, objective, scope_boundary, evidence_plan_json, outcome_metric_json, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,\n ).run(\n contract.goalId,\n contract.version,\n contract.objective,\n contract.scopeBoundary ?? null,\n JSON.stringify(contract.evidencePlan),\n contract.outcomeMetric ? JSON.stringify(contract.outcomeMetric) : null,\n contract.createdAt,\n contract.updatedAt,\n );\n}\n\nfunction eventFromRow(row: EventRow): GoalEvent {\n return {\n id: row.event_id,\n goalId: row.goal_id,\n runId: row.run_id ?? undefined,\n kind: row.kind,\n message: row.message,\n data: parseJsonField(row.data_json),\n createdAt: row.created_at,\n };\n}\n\nfunction evidenceFromRow(row: EvidenceRow): GoalEvidence {\n return {\n id: row.evidence_id,\n goalId: row.goal_id,\n runId: row.run_id ?? undefined,\n kind: row.kind,\n title: row.title,\n summary: row.summary ?? undefined,\n uri: row.uri ?? undefined,\n data: parseJsonField(row.data_json),\n createdAt: row.created_at,\n };\n}\n\nfunction evidenceRequirementFromRow(row: GoalEvidenceRequirementRow, evidenceIds: string[] = []): GoalEvidenceRequirement {\n return {\n id: row.requirement_id,\n goalId: row.goal_id,\n text: row.text,\n status: row.status,\n evidenceIds,\n reviewReason: row.review_reason ?? undefined,\n reviewConfidence: row.review_confidence ?? undefined,\n reviewedBy: row.reviewed_by ?? undefined,\n reviewedAt: row.reviewed_at ?? undefined,\n requiresHumanApproval: Boolean(row.requires_human_approval),\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n sortOrder: row.sort_order,\n };\n}\n\nfunction syncEvidenceRequirements(\n db: ReturnType<typeof getSqliteDatabase>,\n goalId: string,\n evidencePlan: string[],\n now: number,\n): void {\n const existing = db\n .prepare(`SELECT * FROM goal_evidence_requirements WHERE goal_id = ?`)\n .all(goalId) as GoalEvidenceRequirementRow[];\n const byText = new Map(existing.map((item) => [item.text.toLocaleLowerCase(), item]));\n const desired = new Set(evidencePlan.map((text) => text.toLocaleLowerCase()));\n for (const item of existing) {\n if (!desired.has(item.text.toLocaleLowerCase())) {\n db.prepare(`DELETE FROM goal_evidence_requirements WHERE requirement_id = ?`).run(item.requirement_id);\n }\n }\n for (const [index, text] of evidencePlan.entries()) {\n const current = byText.get(text.toLocaleLowerCase());\n if (current) {\n db.prepare(\n `UPDATE goal_evidence_requirements\n SET text = ?, sort_order = ?, updated_at = ?\n WHERE requirement_id = ?`,\n ).run(text, index + 1, now, current.requirement_id);\n } else {\n db.prepare(\n `INSERT INTO goal_evidence_requirements (\n requirement_id, goal_id, text, status, requires_human_approval, created_at, updated_at, sort_order\n ) VALUES (?, ?, ?, 'pending', 1, ?, ?, ?)`,\n ).run(randomUUID(), goalId, text, now, now, index + 1);\n }\n }\n}\n\nfunction clampLimit(n: number | undefined, fallback: number): number {\n return Math.min(500, Math.max(1, Math.floor(n ?? fallback)));\n}\n\nfunction insertGoalEvent(db: ReturnType<typeof getSqliteDatabase>, input: {\n goalId: string;\n runId?: string;\n kind: string;\n message: string;\n data?: unknown;\n createdAt?: number;\n}): GoalEvent {\n const event: GoalEvent = {\n id: randomUUID(),\n goalId: input.goalId,\n runId: input.runId,\n kind: input.kind,\n message: input.message,\n data: input.data,\n createdAt: input.createdAt ?? Date.now(),\n };\n db.prepare(\n `INSERT INTO goal_events (event_id, goal_id, run_id, kind, message, data_json, created_at)\n VALUES (?, ?, ?, ?, ?, ?, ?)`,\n ).run(\n event.id,\n event.goalId,\n event.runId ?? null,\n event.kind,\n event.message,\n event.data === undefined ? null : JSON.stringify(event.data),\n event.createdAt,\n );\n return event;\n}\n\nexport class GoalStore {\n create(input: CreateGoalInput): Goal {\n const now = Date.now();\n const goal: Goal = {\n id: randomUUID(),\n title: input.title.trim(),\n description: input.description?.trim() || undefined,\n status: 'active',\n agentId: input.agentId,\n priority: input.priority ?? 'normal',\n deadlineAt: input.deadlineAt,\n createdAt: now,\n updatedAt: now,\n activeSessionKey: input.sessionKey,\n judgeModelRef: input.judgeModelRef?.trim() || undefined,\n maxTurns: Math.max(1, Math.min(500, Math.floor(input.maxTurns))),\n turnsUsed: 0,\n uiLocale: input.uiLocale,\n source: input.source ?? 'chat',\n projectId: input.projectId?.trim() || undefined,\n };\n const contract = normalizeContract(input.contract, goal.id, goal.title, now);\n const criteria = normalizeStringList(input.contract?.criteria);\n\n runSqliteWriteTransaction((db) => {\n db.prepare(\n `INSERT INTO goals (\n goal_id, title, description, status, agent_id, priority, deadline_at,\n created_at, updated_at, active_session_key, judge_model_ref,\n max_turns, turns_used, ui_locale, source, project_id\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n ).run(\n goal.id,\n goal.title,\n goal.description ?? null,\n goal.status,\n goal.agentId,\n goal.priority,\n goal.deadlineAt ?? null,\n goal.createdAt,\n goal.updatedAt,\n goal.activeSessionKey ?? null,\n goal.judgeModelRef ?? null,\n goal.maxTurns,\n goal.turnsUsed,\n goal.uiLocale ?? null,\n goal.source,\n goal.projectId ?? null,\n );\n if (goal.activeSessionKey) {\n db.prepare(\n `INSERT OR REPLACE INTO goal_session_links (goal_id, session_key, linked_at)\n VALUES (?, ?, ?)`,\n ).run(goal.id, goal.activeSessionKey, now);\n }\n if (contract) {\n insertGoalContract(db, contract);\n syncEvidenceRequirements(db, goal.id, contract.evidencePlan, now);\n for (const [index, text] of criteria.entries()) {\n db.prepare(\n `INSERT INTO goal_checklist_items (\n item_id, goal_id, text, status, added_by, added_at, sort_order\n ) VALUES (?, ?, ?, 'pending', 'user', ?, ?)`,\n ).run(randomUUID(), goal.id, text, now, index + 1);\n }\n insertGoalEvent(db, {\n goalId: goal.id,\n kind: 'contract_created',\n message: contract.objective,\n data: { version: contract.version, criteriaCount: criteria.length, evidenceCount: contract.evidencePlan.length },\n createdAt: now,\n });\n }\n insertGoalEvent(db, { goalId: goal.id, kind: 'created', message: 'Goal created', createdAt: now });\n });\n\n return goal;\n }\n\n get(goalId: string): Goal | null {\n const row = getSqliteDatabase()\n .prepare(`SELECT * FROM goals WHERE goal_id = ?`)\n .get(goalId) as GoalRow | undefined;\n return row ? goalFromRow(row) : null;\n }\n\n setContextMessage(input: {\n goalId: string;\n text: string;\n attachments?: GoalContextAttachment[];\n }): GoalContextMessage {\n return runSqliteWriteTransaction((db) => {\n const now = Date.now();\n const existing = db\n .prepare(`SELECT created_at FROM goal_context_messages WHERE goal_id = ?`)\n .get(input.goalId) as { created_at: number } | undefined;\n db.prepare(\n `INSERT INTO goal_context_messages (goal_id, text, attachments_json, created_at, updated_at)\n VALUES (?, ?, ?, ?, ?)\n ON CONFLICT(goal_id) DO UPDATE SET\n text = excluded.text,\n attachments_json = excluded.attachments_json,\n updated_at = excluded.updated_at`,\n ).run(\n input.goalId,\n input.text.trim(),\n JSON.stringify(input.attachments ?? []),\n existing?.created_at ?? now,\n now,\n );\n insertGoalEvent(db, {\n goalId: input.goalId,\n kind: 'context_updated',\n message: input.text.trim() || `${input.attachments?.length ?? 0} attachment(s)`,\n data: { attachmentCount: input.attachments?.length ?? 0 },\n createdAt: now,\n });\n const row = db\n .prepare(`SELECT * FROM goal_context_messages WHERE goal_id = ?`)\n .get(input.goalId) as GoalContextRow;\n return goalContextFromRow(row);\n });\n }\n\n getContextMessage(goalId: string): GoalContextMessage | null {\n const row = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_context_messages WHERE goal_id = ?`)\n .get(goalId) as GoalContextRow | undefined;\n return row ? goalContextFromRow(row) : null;\n }\n\n getContract(goalId: string): GoalContract | null {\n const row = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_contracts WHERE goal_id = ?`)\n .get(goalId) as GoalContractRow | undefined;\n return row ? goalContractFromRow(row) : null;\n }\n\n setContract(goalId: string, input: GoalContractInput): GoalContract | null {\n const goal = this.get(goalId);\n if (!goal) return null;\n return runSqliteWriteTransaction((db) => {\n const existing = db\n .prepare(`SELECT * FROM goal_contracts WHERE goal_id = ?`)\n .get(goalId) as GoalContractRow | undefined;\n const now = Date.now();\n const contract = normalizeContract(\n {\n ...input,\n objective: input.objective ?? existing?.objective,\n scopeBoundary: input.scopeBoundary ?? existing?.scope_boundary ?? undefined,\n evidencePlan: input.evidencePlan ?? parseJsonStringArray(existing?.evidence_plan_json ?? null) ?? [],\n outcomeMetric: input.outcomeMetric === undefined\n ? parseGoalOutcomeMetric(existing?.outcome_metric_json ?? null)\n : input.outcomeMetric,\n },\n goalId,\n goal.title,\n now,\n (existing?.version ?? 0) + 1,\n existing?.created_at ?? now,\n );\n if (!contract) return null;\n db.prepare(\n `INSERT INTO goal_contracts (\n goal_id, version, objective, scope_boundary, evidence_plan_json, outcome_metric_json, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)\n ON CONFLICT(goal_id) DO UPDATE SET\n version = excluded.version,\n objective = excluded.objective,\n scope_boundary = excluded.scope_boundary,\n evidence_plan_json = excluded.evidence_plan_json,\n outcome_metric_json = excluded.outcome_metric_json,\n updated_at = excluded.updated_at`,\n ).run(\n contract.goalId,\n contract.version,\n contract.objective,\n contract.scopeBoundary ?? null,\n JSON.stringify(contract.evidencePlan),\n contract.outcomeMetric ? JSON.stringify(contract.outcomeMetric) : null,\n contract.createdAt,\n contract.updatedAt,\n );\n syncEvidenceRequirements(db, goalId, contract.evidencePlan, now);\n insertGoalEvent(db, {\n goalId,\n kind: 'contract_updated',\n message: contract.objective,\n data: {\n version: contract.version,\n evidenceCount: contract.evidencePlan.length,\n hasOutcomeMetric: Boolean(contract.outcomeMetric),\n },\n createdAt: now,\n });\n return contract;\n });\n }\n\n getActiveForSession(sessionKey: string): Goal | null {\n const row = getSqliteDatabase()\n .prepare(\n `SELECT * FROM goals\n WHERE active_session_key = ?\n AND status IN ('active', 'paused', 'blocked', 'needs_input', 'done')\n ORDER BY updated_at DESC\n LIMIT 1`,\n )\n .get(sessionKey) as GoalRow | undefined;\n return row ? goalFromRow(row) : null;\n }\n\n list(query: GoalListQuery = {}): Goal[] {\n const conditions: string[] = [];\n const params: Array<string | number> = [];\n if (query.status) {\n const statuses = Array.isArray(query.status) ? query.status : [query.status];\n conditions.push(`status IN (${statuses.map(() => '?').join(', ')})`);\n params.push(...statuses);\n }\n if (query.agentId) {\n conditions.push(`agent_id = ?`);\n params.push(query.agentId);\n }\n if (query.sessionKey) {\n conditions.push(`goal_id IN (SELECT goal_id FROM goal_session_links WHERE session_key = ?)`);\n params.push(query.sessionKey);\n }\n if (query.projectId) {\n conditions.push(`project_id = ?`);\n params.push(query.projectId);\n }\n const where = conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';\n const limit = clampLimit(query.limit, 50);\n const offset = Math.max(0, Math.floor(query.offset ?? 0));\n const rows = getSqliteDatabase()\n .prepare(`SELECT * FROM goals ${where} ORDER BY updated_at DESC LIMIT ? OFFSET ?`)\n .all(...params, limit, offset) as GoalRow[];\n return rows.map(goalFromRow);\n }\n\n update(goalId: string, patch: Partial<Pick<\n Goal,\n | 'title'\n | 'description'\n | 'status'\n | 'priority'\n | 'deadlineAt'\n | 'completedAt'\n | 'archivedAt'\n | 'activeSessionKey'\n | 'currentRunId'\n | 'nextAction'\n | 'blockedReason'\n | 'judgeModelRef'\n | 'maxTurns'\n | 'turnsUsed'\n | 'uiLocale'\n | 'projectId'\n >>): Goal | null {\n const before = this.get(goalId);\n if (!before) return null;\n const next = { ...before, ...patch, updatedAt: Date.now() };\n runSqliteWriteTransaction((db) => {\n db.prepare(\n `UPDATE goals SET\n title = ?, description = ?, status = ?, priority = ?, deadline_at = ?,\n updated_at = ?, completed_at = ?, archived_at = ?, active_session_key = ?,\n current_run_id = ?, next_action = ?, blocked_reason = ?, judge_model_ref = ?,\n max_turns = ?, turns_used = ?, ui_locale = ?, project_id = ?\n WHERE goal_id = ?`,\n ).run(\n next.title,\n next.description ?? null,\n next.status,\n next.priority,\n next.deadlineAt ?? null,\n next.updatedAt,\n next.completedAt ?? null,\n next.archivedAt ?? null,\n next.activeSessionKey ?? null,\n next.currentRunId ?? null,\n next.nextAction ?? null,\n next.blockedReason ?? null,\n next.judgeModelRef ?? null,\n next.maxTurns,\n next.turnsUsed,\n next.uiLocale ?? null,\n next.projectId ?? null,\n goalId,\n );\n if (next.activeSessionKey) {\n db.prepare(\n `INSERT OR REPLACE INTO goal_session_links (goal_id, session_key, linked_at)\n VALUES (?, ?, ?)`,\n ).run(goalId, next.activeSessionKey, next.updatedAt);\n }\n });\n return this.get(goalId);\n }\n\n listChecklist(goalId: string): GoalChecklistItem[] {\n const rows = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_checklist_items WHERE goal_id = ? ORDER BY sort_order ASC, added_at ASC`)\n .all(goalId) as ChecklistRow[];\n return rows.map(checklistFromRow);\n }\n\n addChecklistItem(input: {\n goalId: string;\n text: string;\n addedBy: GoalChecklistAddedBy;\n status?: GoalChecklistStatus;\n }): GoalChecklistItem {\n return runSqliteWriteTransaction((db) => {\n const maxRow = db\n .prepare(`SELECT COALESCE(MAX(sort_order), 0) AS max_sort FROM goal_checklist_items WHERE goal_id = ?`)\n .get(input.goalId) as { max_sort: number };\n const now = Date.now();\n const item: GoalChecklistItem = {\n id: randomUUID(),\n goalId: input.goalId,\n text: input.text.trim(),\n status: input.status ?? 'pending',\n addedBy: input.addedBy,\n addedAt: now,\n sortOrder: maxRow.max_sort + 1,\n };\n db.prepare(\n `INSERT INTO goal_checklist_items (\n item_id, goal_id, text, status, added_by, added_at, sort_order\n ) VALUES (?, ?, ?, ?, ?, ?, ?)`,\n ).run(item.id, item.goalId, item.text, item.status, item.addedBy, item.addedAt, item.sortOrder);\n insertGoalEvent(db, {\n goalId: input.goalId,\n kind: 'checklist_added',\n message: item.text,\n data: { itemId: item.id, addedBy: item.addedBy },\n createdAt: now,\n });\n return item;\n });\n }\n\n updateChecklistItem(\n itemId: string,\n patch: Partial<Pick<GoalChecklistItem, 'text' | 'status' | 'evidenceSummary'>>,\n ): GoalChecklistItem | null {\n return runSqliteWriteTransaction((db) => {\n const row = db\n .prepare(`SELECT * FROM goal_checklist_items WHERE item_id = ?`)\n .get(itemId) as ChecklistRow | undefined;\n if (!row) return null;\n const before = checklistFromRow(row);\n const status = patch.status ?? before.status;\n const completedAt =\n status === 'completed' || status === 'impossible'\n ? (before.completedAt ?? Date.now())\n : null;\n db.prepare(\n `UPDATE goal_checklist_items SET text = ?, status = ?, completed_at = ?, evidence_summary = ?\n WHERE item_id = ?`,\n ).run(\n patch.text?.trim() || before.text,\n status,\n completedAt,\n patch.evidenceSummary ?? before.evidenceSummary ?? null,\n itemId,\n );\n insertGoalEvent(db, {\n goalId: before.goalId,\n kind: 'checklist_updated',\n message: patch.text?.trim() || before.text,\n data: { itemId, status },\n });\n const next = db\n .prepare(`SELECT * FROM goal_checklist_items WHERE item_id = ?`)\n .get(itemId) as ChecklistRow;\n return checklistFromRow(next);\n });\n }\n\n removeChecklistItem(itemId: string): boolean {\n return runSqliteWriteTransaction((db) => {\n const row = db\n .prepare(`SELECT goal_id, text FROM goal_checklist_items WHERE item_id = ?`)\n .get(itemId) as { goal_id: string; text: string } | undefined;\n if (!row) return false;\n db.prepare(`DELETE FROM goal_checklist_items WHERE item_id = ?`).run(itemId);\n insertGoalEvent(db, {\n goalId: row.goal_id,\n kind: 'checklist_removed',\n message: row.text,\n data: { itemId },\n });\n return true;\n });\n }\n\n clearChecklist(goalId: string): void {\n runSqliteWriteTransaction((db) => {\n db.prepare(`DELETE FROM goal_checklist_items WHERE goal_id = ?`).run(goalId);\n insertGoalEvent(db, { goalId, kind: 'checklist_cleared', message: 'Checklist cleared' });\n });\n }\n\n replaceChecklist(goalId: string, items: Array<{\n text: string;\n status: GoalChecklistStatus;\n addedBy: GoalChecklistAddedBy;\n addedAt?: number;\n completedAt?: number;\n evidenceSummary?: string;\n }>): GoalChecklistItem[] {\n return runSqliteWriteTransaction((db) => {\n db.prepare(`DELETE FROM goal_checklist_items WHERE goal_id = ?`).run(goalId);\n const now = Date.now();\n const next: GoalChecklistItem[] = [];\n for (let i = 0; i < items.length; i++) {\n const raw = items[i]!;\n const item: GoalChecklistItem = {\n id: randomUUID(),\n goalId,\n text: raw.text.trim(),\n status: raw.status,\n addedBy: raw.addedBy,\n addedAt: raw.addedAt ?? now,\n completedAt: raw.completedAt,\n evidenceSummary: raw.evidenceSummary,\n sortOrder: i + 1,\n };\n if (!item.text) continue;\n db.prepare(\n `INSERT INTO goal_checklist_items (\n item_id, goal_id, text, status, added_by, added_at, completed_at, evidence_summary, sort_order\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n ).run(\n item.id,\n item.goalId,\n item.text,\n item.status,\n item.addedBy,\n item.addedAt,\n item.completedAt ?? null,\n item.evidenceSummary ?? null,\n item.sortOrder,\n );\n next.push(item);\n }\n insertGoalEvent(db, {\n goalId,\n kind: 'checklist_replaced',\n message: `Checklist replaced (${next.length} items)`,\n });\n return next;\n });\n }\n\n appendRun(run: Omit<GoalRun, 'id' | 'startedAt'> & { id?: string; startedAt?: number }): GoalRun {\n const record: GoalRun = {\n id: run.id ?? randomUUID(),\n goalId: run.goalId,\n sessionKey: run.sessionKey,\n source: run.source,\n status: run.status,\n startedAt: run.startedAt ?? Date.now(),\n finishedAt: run.finishedAt,\n verdict: run.verdict,\n reason: run.reason,\n nextAction: run.nextAction,\n assistantPreview: run.assistantPreview,\n checklistProgress: run.checklistProgress,\n };\n runSqliteWriteTransaction((db) => {\n db.prepare(\n `INSERT INTO goal_runs (\n run_id, goal_id, session_key, source, status, started_at, finished_at,\n verdict, reason, next_action, assistant_preview, checklist_done, checklist_total,\n confidence, missing_evidence_json, user_question, completed_checklist_item_ids_json\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n ).run(\n record.id,\n record.goalId,\n record.sessionKey,\n record.source,\n record.status,\n record.startedAt,\n record.finishedAt ?? null,\n record.verdict ?? null,\n record.reason ?? null,\n record.nextAction ?? null,\n record.assistantPreview ?? null,\n record.checklistProgress?.done ?? null,\n record.checklistProgress?.total ?? null,\n record.confidence ?? null,\n record.missingEvidence ? JSON.stringify(record.missingEvidence) : null,\n record.userQuestion ?? null,\n record.completedChecklistItemIds ? JSON.stringify(record.completedChecklistItemIds) : null,\n );\n db.prepare(`UPDATE goals SET current_run_id = ?, updated_at = ? WHERE goal_id = ?`).run(\n record.id,\n record.finishedAt ?? record.startedAt,\n record.goalId,\n );\n insertGoalEvent(db, {\n goalId: record.goalId,\n runId: record.id,\n kind: 'run_recorded',\n message: record.reason ?? record.status,\n data: {\n verdict: record.verdict,\n status: record.status,\n confidence: record.confidence,\n missingEvidence: record.missingEvidence,\n userQuestion: record.userQuestion,\n completedChecklistItemIds: record.completedChecklistItemIds,\n },\n createdAt: record.finishedAt ?? record.startedAt,\n });\n });\n return record;\n }\n\n listRuns(goalId: string, limit?: number): GoalRun[] {\n const rows = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_runs WHERE goal_id = ? ORDER BY started_at DESC LIMIT ?`)\n .all(goalId, clampLimit(limit, 50)) as GoalRunRow[];\n return rows.map(runFromRow);\n }\n\n listRunsForSession(sessionKey: string, limit?: number): GoalRun[] {\n const rows = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_runs WHERE session_key = ? ORDER BY started_at DESC LIMIT ?`)\n .all(sessionKey, clampLimit(limit, 50)) as GoalRunRow[];\n return rows.map(runFromRow);\n }\n\n listEvents(goalId: string, limit?: number): GoalEvent[] {\n const rows = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_events WHERE goal_id = ? ORDER BY created_at DESC LIMIT ?`)\n .all(goalId, clampLimit(limit, 100)) as EventRow[];\n return rows.map(eventFromRow);\n }\n\n addEvidence(input: Omit<GoalEvidence, 'id' | 'createdAt'> & { id?: string; createdAt?: number }): GoalEvidence {\n const evidence: GoalEvidence = {\n id: input.id ?? randomUUID(),\n goalId: input.goalId,\n runId: input.runId,\n kind: input.kind,\n title: input.title,\n summary: input.summary,\n uri: input.uri,\n data: input.data,\n createdAt: input.createdAt ?? Date.now(),\n };\n runSqliteWriteTransaction((db) => {\n db.prepare(\n `INSERT INTO goal_evidence (\n evidence_id, goal_id, run_id, kind, title, summary, uri, data_json, created_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n ).run(\n evidence.id,\n evidence.goalId,\n evidence.runId ?? null,\n evidence.kind,\n evidence.title,\n evidence.summary ?? null,\n evidence.uri ?? null,\n evidence.data === undefined ? null : JSON.stringify(evidence.data),\n evidence.createdAt,\n );\n insertGoalEvent(db, {\n goalId: evidence.goalId,\n runId: evidence.runId,\n kind: 'evidence_added',\n message: evidence.title,\n data: { evidenceId: evidence.id, kind: evidence.kind },\n createdAt: evidence.createdAt,\n });\n });\n return evidence;\n }\n\n listEvidence(goalId: string, limit?: number): GoalEvidence[] {\n const rows = getSqliteDatabase()\n .prepare(`SELECT * FROM goal_evidence WHERE goal_id = ? ORDER BY created_at DESC LIMIT ?`)\n .all(goalId, clampLimit(limit, 100)) as EvidenceRow[];\n const db = getSqliteDatabase();\n return rows.map((row) => ({\n ...evidenceFromRow(row),\n requirementIds: (db.prepare(\n `SELECT requirement_id FROM goal_evidence_requirement_links WHERE evidence_id = ? ORDER BY requirement_id`,\n ).all(row.evidence_id) as Array<{ requirement_id: string }>).map((item) => item.requirement_id),\n }));\n }\n\n listEvidenceRequirements(goalId: string): GoalEvidenceRequirement[] {\n const db = getSqliteDatabase();\n const rows = db\n .prepare(`SELECT * FROM goal_evidence_requirements WHERE goal_id = ? ORDER BY sort_order ASC`)\n .all(goalId) as GoalEvidenceRequirementRow[];\n return rows.map((row) => evidenceRequirementFromRow(\n row,\n (db.prepare(\n `SELECT evidence_id FROM goal_evidence_requirement_links WHERE requirement_id = ? ORDER BY created_at ASC`,\n ).all(row.requirement_id) as Array<{ evidence_id: string }>).map((item) => item.evidence_id),\n ));\n }\n\n linkEvidenceRequirement(input: {\n goalId: string;\n requirementId: string;\n evidenceId: string;\n linkedBy: 'user' | 'agent' | 'system';\n }): GoalEvidenceRequirement | null {\n return runSqliteWriteTransaction((db) => {\n const requirement = db.prepare(\n `SELECT * FROM goal_evidence_requirements WHERE requirement_id = ? AND goal_id = ?`,\n ).get(input.requirementId, input.goalId) as GoalEvidenceRequirementRow | undefined;\n const evidence = db.prepare(\n `SELECT evidence_id FROM goal_evidence WHERE evidence_id = ? AND goal_id = ?`,\n ).get(input.evidenceId, input.goalId) as { evidence_id: string } | undefined;\n if (!requirement || !evidence) return null;\n const now = Date.now();\n db.prepare(\n `INSERT OR IGNORE INTO goal_evidence_requirement_links (requirement_id, evidence_id, linked_by, created_at)\n VALUES (?, ?, ?, ?)`,\n ).run(input.requirementId, input.evidenceId, input.linkedBy, now);\n db.prepare(\n `UPDATE goal_evidence_requirements\n SET status = CASE WHEN status = 'rejected' THEN 'pending' ELSE status END,\n updated_at = ?\n WHERE requirement_id = ?`,\n ).run(now, input.requirementId);\n insertGoalEvent(db, {\n goalId: input.goalId,\n kind: 'evidence_requirement_linked',\n message: requirement.text,\n data: { requirementId: input.requirementId, evidenceId: input.evidenceId, linkedBy: input.linkedBy },\n createdAt: now,\n });\n const ids = (db.prepare(\n `SELECT evidence_id FROM goal_evidence_requirement_links WHERE requirement_id = ? ORDER BY created_at ASC`,\n ).all(input.requirementId) as Array<{ evidence_id: string }>).map((item) => item.evidence_id);\n const next = db.prepare(`SELECT * FROM goal_evidence_requirements WHERE requirement_id = ?`)\n .get(input.requirementId) as GoalEvidenceRequirementRow;\n return evidenceRequirementFromRow(next, ids);\n });\n }\n\n reviewEvidenceRequirement(input: {\n goalId: string;\n requirementId: string;\n status: GoalEvidenceRequirementStatus;\n reason: string;\n confidence?: number;\n reviewedBy: GoalEvidenceReviewSource;\n }): GoalEvidenceRequirement | null {\n return runSqliteWriteTransaction((db) => {\n const current = db.prepare(\n `SELECT * FROM goal_evidence_requirements WHERE requirement_id = ? AND goal_id = ?`,\n ).get(input.requirementId, input.goalId) as GoalEvidenceRequirementRow | undefined;\n if (!current) return null;\n const now = Date.now();\n db.prepare(\n `UPDATE goal_evidence_requirements\n SET status = ?, review_reason = ?, review_confidence = ?, reviewed_by = ?, reviewed_at = ?, updated_at = ?\n WHERE requirement_id = ?`,\n ).run(\n input.status,\n input.reason.trim(),\n input.confidence ?? null,\n input.reviewedBy,\n now,\n now,\n input.requirementId,\n );\n insertGoalEvent(db, {\n goalId: input.goalId,\n kind: input.reviewedBy === 'user' ? 'evidence_requirement_approved' : 'evidence_requirement_reviewed',\n message: current.text,\n data: { requirementId: input.requirementId, status: input.status, reason: input.reason.trim(), confidence: input.confidence },\n createdAt: now,\n });\n const ids = (db.prepare(\n `SELECT evidence_id FROM goal_evidence_requirement_links WHERE requirement_id = ? ORDER BY created_at ASC`,\n ).all(input.requirementId) as Array<{ evidence_id: string }>).map((item) => item.evidence_id);\n const next = db.prepare(`SELECT * FROM goal_evidence_requirements WHERE requirement_id = ?`)\n .get(input.requirementId) as GoalEvidenceRequirementRow;\n return evidenceRequirementFromRow(next, ids);\n });\n }\n}\n"],"mappings":";;;AA4IA,SAAS,YAAY,KAAoB;AACvC,QAAO;EACL,IAAI,IAAI;EACR,OAAO,IAAI;EACX,aAAa,IAAI,eAAe,KAAA;EAChC,QAAQ,IAAI;EACZ,SAAS,IAAI;EACb,UAAU,IAAI;EACd,YAAY,IAAI,eAAe,KAAA;EAC/B,WAAW,IAAI;EACf,WAAW,IAAI;EACf,aAAa,IAAI,gBAAgB,KAAA;EACjC,YAAY,IAAI,eAAe,KAAA;EAC/B,kBAAkB,IAAI,sBAA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oC,KAAK,SAAS,KAAK,YAAY;AAG7F,UAAO,2BAFM,GAAG,QAAQ,oEAAoE,CACzF,IAAI,MAAM,cACyB,EAAE,IAAI;IAC5C;;CAGJ,0BAA0B,OAOS;AACjC,SAAO,2BAA2B,OAAO;GACvC,MAAM,UAAU,GAAG,QACjB,oFACD,CAAC,IAAI,MAAM,eAAe,MAAM,OAAO;AACxC,OAAI,CAAC,QAAS,QAAO;GACrB,MAAM,MAAM,KAAK,KAAK;AACtB,MAAG,QACD;;mCAGD,CAAC,IACA,MAAM,QACN,MAAM,OAAO,MAAM,EACnB,MAAM,cAAc,MACpB,MAAM,YACN,KACA,KACA,MAAM,cACP;AACD,mBAAgB,IAAI;IAClB,QAAQ,MAAM;IACd,MAAM,MAAM,eAAe,SAAS,kCAAkC;IACtE,SAAS,QAAQ;IACjB,MAAM;KAAE,eAAe,MAAM;KAAe,QAAQ,MAAM;KAAQ,QAAQ,MAAM,OAAO,MAAM;KAAE,YAAY,MAAM;KAAY;IAC7H,WAAW;IACZ,CAAC;GACF,MAAM,MAAO,GAAG,QACd,2GACD,CAAC,IAAI,MAAM,cAAc,CAAoC,KAAK,SAAS,KAAK,YAAY;AAG7F,UAAO,2BAFM,GAAG,QAAQ,oEAAoE,CACzF,IAAI,MAAM,cACyB,EAAE,IAAI;IAC5C"}
|
|
@@ -120,14 +120,38 @@ export interface GoalContract {
|
|
|
120
120
|
objective: string;
|
|
121
121
|
scopeBoundary?: string;
|
|
122
122
|
evidencePlan: string[];
|
|
123
|
+
outcomeMetric?: GoalOutcomeMetric;
|
|
123
124
|
createdAt: number;
|
|
124
125
|
updatedAt: number;
|
|
125
126
|
}
|
|
127
|
+
export type GoalOutcomeDirection = 'increase' | 'decrease';
|
|
128
|
+
/** A measurable user-visible result used to verify that outputs changed the intended outcome. */
|
|
129
|
+
export interface GoalOutcomeMetric {
|
|
130
|
+
name: string;
|
|
131
|
+
baselineValue: number;
|
|
132
|
+
targetValue: number;
|
|
133
|
+
currentValue?: number;
|
|
134
|
+
unit?: string;
|
|
135
|
+
direction: GoalOutcomeDirection;
|
|
136
|
+
sourceUrl?: string;
|
|
137
|
+
measuredAt?: number;
|
|
138
|
+
}
|
|
139
|
+
export interface GoalOutcomeMetricInput {
|
|
140
|
+
name: string;
|
|
141
|
+
baselineValue: number;
|
|
142
|
+
targetValue: number;
|
|
143
|
+
currentValue?: number;
|
|
144
|
+
unit?: string;
|
|
145
|
+
direction?: GoalOutcomeDirection;
|
|
146
|
+
sourceUrl?: string;
|
|
147
|
+
measuredAt?: number;
|
|
148
|
+
}
|
|
126
149
|
export interface GoalContractInput {
|
|
127
150
|
objective?: string;
|
|
128
151
|
scopeBoundary?: string;
|
|
129
152
|
evidencePlan?: string[];
|
|
130
153
|
criteria?: string[];
|
|
154
|
+
outcomeMetric?: GoalOutcomeMetricInput | null;
|
|
131
155
|
}
|
|
132
156
|
export interface GoalWithDetails extends Goal {
|
|
133
157
|
checklist: GoalChecklistItem[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ConnectorActionMetadata, ConnectorApprovalRecord, ConnectorConnection, ConnectorDefinition, ConnectorExecutionAuditRecord, ConnectorInstallationPolicy } from '../../connectors/types.js';
|
|
2
|
+
export type CachedConnectorCatalogEntry = {
|
|
3
|
+
connectorId: string;
|
|
4
|
+
provider: string;
|
|
5
|
+
definition: ConnectorDefinition;
|
|
6
|
+
fetchedAt: string;
|
|
7
|
+
expiresAt?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function createConnectorApproval(input: Omit<ConnectorApprovalRecord, 'id' | 'status' | 'createdAt'> & Partial<Pick<ConnectorApprovalRecord, 'id' | 'status' | 'createdAt'>>): ConnectorApprovalRecord;
|
|
10
|
+
export declare function getConnectorApproval(id: string): ConnectorApprovalRecord | undefined;
|
|
11
|
+
export declare function listConnectorApprovals(options?: {
|
|
12
|
+
principalId?: string;
|
|
13
|
+
sessionKey?: string;
|
|
14
|
+
status?: ConnectorApprovalRecord['status'];
|
|
15
|
+
limit?: number;
|
|
16
|
+
}): ConnectorApprovalRecord[];
|
|
17
|
+
export declare function decideConnectorApproval(id: string, decision: 'approved' | 'denied', now?: Date): ConnectorApprovalRecord | undefined;
|
|
18
|
+
export declare function consumeConnectorApproval(id: string, argumentsHash: string, now?: Date): ConnectorApprovalRecord | undefined;
|
|
19
|
+
export declare function upsertConnectorCatalogEntry(input: CachedConnectorCatalogEntry): CachedConnectorCatalogEntry;
|
|
20
|
+
export declare function getCachedConnectorCatalogEntry(connectorId: string): CachedConnectorCatalogEntry | undefined;
|
|
21
|
+
export declare function listCachedConnectorCatalogEntries(provider?: string): CachedConnectorCatalogEntry[];
|
|
22
|
+
export declare function upsertConnectorInstallation(input: Omit<ConnectorInstallationPolicy, 'createdAt' | 'updatedAt'> & Partial<Pick<ConnectorInstallationPolicy, 'createdAt' | 'updatedAt'>>): ConnectorInstallationPolicy;
|
|
23
|
+
export declare function getConnectorInstallation(id: string): ConnectorInstallationPolicy | undefined;
|
|
24
|
+
export declare function listConnectorInstallations(principalId?: string): ConnectorInstallationPolicy[];
|
|
25
|
+
export declare function deleteConnectorInstallation(id: string): boolean;
|
|
26
|
+
export declare function upsertConnectorConnection(input: Omit<ConnectorConnection, 'createdAt' | 'updatedAt'> & Partial<Pick<ConnectorConnection, 'createdAt' | 'updatedAt'>>): ConnectorConnection;
|
|
27
|
+
export declare function getConnectorConnection(id: string): ConnectorConnection | undefined;
|
|
28
|
+
export declare function listConnectorConnections(options?: {
|
|
29
|
+
principalId?: string;
|
|
30
|
+
connectorId?: string;
|
|
31
|
+
}): ConnectorConnection[];
|
|
32
|
+
export declare function deleteConnectorConnection(id: string): boolean;
|
|
33
|
+
export declare function upsertConnectorActionMetadata(input: ConnectorActionMetadata): ConnectorActionMetadata;
|
|
34
|
+
export declare function listConnectorActionMetadata(connectorId: string): ConnectorActionMetadata[];
|
|
35
|
+
export declare function appendConnectorExecutionAudit(input: Omit<ConnectorExecutionAuditRecord, 'id' | 'createdAt'> & Partial<Pick<ConnectorExecutionAuditRecord, 'id' | 'createdAt'>>): ConnectorExecutionAuditRecord;
|
|
36
|
+
export declare function listConnectorExecutionAudit(options?: {
|
|
37
|
+
principalId?: string;
|
|
38
|
+
connectorId?: string;
|
|
39
|
+
limit?: number;
|
|
40
|
+
}): ConnectorExecutionAuditRecord[];
|
|
41
|
+
export declare function claimConnectorWebhookDelivery(input: {
|
|
42
|
+
id: string;
|
|
43
|
+
provider: string;
|
|
44
|
+
payloadHash: string;
|
|
45
|
+
now?: Date;
|
|
46
|
+
leaseMs?: number;
|
|
47
|
+
}): 'claimed' | 'processed' | 'in_flight';
|
|
48
|
+
export declare function completeConnectorWebhookDelivery(id: string, now?: Date): void;
|
|
49
|
+
export declare function releaseConnectorWebhookDelivery(id: string, error: unknown): void;
|