@agent-native/core 0.113.0 → 0.114.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-native.eject.json +164 -0
- package/corpus/README.md +3 -3
- package/corpus/core/CHANGELOG.md +20 -0
- package/corpus/core/README.md +61 -174
- package/corpus/core/agent-native.eject.json +164 -0
- package/corpus/core/docs/content/agent-native-toolkit.mdx +38 -0
- package/corpus/core/docs/content/package-lifecycle.mdx +54 -4
- package/corpus/core/package.json +15 -2
- package/corpus/core/src/cli/eject.ts +1594 -0
- package/corpus/core/src/cli/index.ts +16 -0
- package/corpus/core/src/client/build-compatibility.ts +77 -0
- package/corpus/core/src/client/index.ts +4 -0
- package/corpus/core/src/client/resources/McpConnectionSuggestion.tsx +8 -2
- package/corpus/core/src/client/resources/McpIntegrationDialog.tsx +7 -2
- package/corpus/core/src/client/resources/ResourcesPanel.tsx +17 -3
- package/corpus/core/src/client/resources/index.ts +19 -0
- package/corpus/core/src/client/resources/mcp-integration-catalog.ts +9 -1
- package/corpus/core/src/client/resources/runtime.ts +1 -0
- package/corpus/core/src/client/route-chunk-recovery/index.ts +1 -0
- package/corpus/core/src/client/setup-connections/catalog.ts +6 -0
- package/corpus/core/src/client/setup-connections/index.ts +1 -0
- package/corpus/core/src/client/setup-connections/runtime.ts +1 -0
- package/corpus/core/src/client/use-action.ts +32 -1
- package/corpus/core/src/connections/catalog.ts +41 -24
- package/corpus/core/src/connections/index.ts +1 -0
- package/corpus/core/src/connections/runtime.ts +1 -0
- package/corpus/core/src/deploy/build.ts +4 -1
- package/corpus/core/src/eject/provider-api-definitions.ts +193 -0
- package/corpus/core/src/eject/remote-mcp-presets.ts +137 -0
- package/corpus/core/src/eject/setup-readiness-ui.tsx +29 -0
- package/corpus/core/src/eject/workspace-connections.ts +92 -0
- package/corpus/core/src/index.ts +1 -0
- package/corpus/core/src/integrations/adapter-overrides.ts +12 -0
- package/corpus/core/src/integrations/eject/messaging-adapters.ts +85 -0
- package/corpus/core/src/integrations/index.ts +5 -1
- package/corpus/core/src/integrations/plugin.ts +34 -12
- package/corpus/core/src/integrations/runtime.ts +1 -0
- package/corpus/core/src/integrations/types.ts +3 -1
- package/corpus/core/src/org/context.ts +56 -30
- package/corpus/core/src/package-lifecycle/eject-manifest.ts +345 -0
- package/corpus/core/src/package-lifecycle/index.ts +1 -0
- package/corpus/core/src/provider-api/index.ts +46 -12
- package/corpus/core/src/provider-api/runtime.ts +1 -0
- package/corpus/core/src/server/action-routes.ts +52 -2
- package/corpus/core/src/server/auth-plugin.ts +9 -4
- package/corpus/core/src/server/better-auth-instance.ts +5 -1
- package/corpus/core/src/setup-connections/index.ts +1 -0
- package/corpus/core/src/shared/mcp-embed-headers.ts +1 -1
- package/corpus/core/src/shared/merge-by-id.ts +14 -0
- package/corpus/core/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/core/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/core/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/core/src/templates/default/AGENTS.md +6 -5
- package/corpus/core/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/core/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/core/src/templates/headless/AGENTS.md +5 -4
- package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
- package/corpus/core/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/core/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/core/src/templates/workspace-core/AGENTS.md +4 -4
- package/corpus/core/src/templates/workspace-root/AGENTS.md +4 -4
- package/corpus/core/src/vite/client.ts +42 -2
- package/corpus/templates/analytics/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/analytics/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/assets/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/assets/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/brain/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/brain/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/brain/actions/remediate-legacy-capture-audiences.ts +167 -0
- package/corpus/templates/brain/app/lib/brain-chat-readiness.ts +6 -0
- package/corpus/templates/brain/app/routes/_index.tsx +8 -0
- package/corpus/templates/brain/app/routes.ts +1 -0
- package/corpus/templates/brain/changelog/2026-07-19-ask-starts-immediately-when-builder-s-managed-ai-connection-.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-19-slack-and-granola-backfills-now-process-captures-concurrentl.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-19-source-review-settings-now-control-knowledge-approval.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-19-the-manage-agent-page-now-opens-correctly-from-brain-navigat.md +6 -0
- package/corpus/templates/brain/server/db/schema.ts +3 -0
- package/corpus/templates/brain/server/lib/brain.ts +41 -2
- package/corpus/templates/brain/server/lib/connectors.ts +379 -113
- package/corpus/templates/brain/server/lib/meeting-audience.ts +38 -0
- package/corpus/templates/brain/server/plugins/db.ts +10 -0
- package/corpus/templates/brain/server/routes/api/_agent-native/brain/ingest.post.ts +6 -4
- package/corpus/templates/calendar/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/calendar/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/chat/AGENTS.md +3 -2
- package/corpus/templates/clips/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/clips/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/content/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/content/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/content/AGENTS.md +2 -0
- package/corpus/templates/content/actions/_content-database-personal-view.ts +49 -5
- package/corpus/templates/content/actions/_content-document-access.ts +21 -0
- package/corpus/templates/content/actions/_content-favorites.ts +91 -0
- package/corpus/templates/content/actions/_content-files.ts +79 -23
- package/corpus/templates/content/actions/_content-sidebar-state.ts +24 -0
- package/corpus/templates/content/actions/_content-space-access.ts +15 -17
- package/corpus/templates/content/actions/_content-space-catalog-guards.ts +20 -0
- package/corpus/templates/content/actions/_content-spaces.ts +364 -167
- package/corpus/templates/content/actions/_database-source-utils.ts +8 -0
- package/corpus/templates/content/actions/_database-utils.ts +249 -15
- package/corpus/templates/content/actions/_delete-content-space.ts +84 -0
- package/corpus/templates/content/actions/_files-system-properties.ts +499 -0
- package/corpus/templates/content/actions/_local-file-documents.ts +0 -1
- package/corpus/templates/content/actions/_property-utils.ts +18 -9
- package/corpus/templates/content/actions/bind-content-database-source-field.ts +3 -0
- package/corpus/templates/content/actions/configure-document-property.ts +3 -0
- package/corpus/templates/content/actions/create-content-database.ts +2 -2
- package/corpus/templates/content/actions/create-content-space.ts +34 -0
- package/corpus/templates/content/actions/create-document.ts +4 -1
- package/corpus/templates/content/actions/delete-content-space.ts +19 -0
- package/corpus/templates/content/actions/delete-database-items.ts +28 -1
- package/corpus/templates/content/actions/delete-document-property.ts +3 -0
- package/corpus/templates/content/actions/delete-document.ts +39 -2
- package/corpus/templates/content/actions/duplicate-database-item.ts +6 -0
- package/corpus/templates/content/actions/duplicate-database-items.ts +6 -0
- package/corpus/templates/content/actions/duplicate-document-property.ts +3 -0
- package/corpus/templates/content/actions/get-content-database.ts +11 -2
- package/corpus/templates/content/actions/get-content-sidebar-state.ts +23 -0
- package/corpus/templates/content/actions/get-document.ts +32 -7
- package/corpus/templates/content/actions/import-content-source.ts +33 -1
- package/corpus/templates/content/actions/list-content-spaces.ts +34 -2
- package/corpus/templates/content/actions/list-documents.ts +39 -7
- package/corpus/templates/content/actions/reorder-document-property.ts +9 -0
- package/corpus/templates/content/actions/set-document-property.ts +41 -23
- package/corpus/templates/content/actions/share-local-file-document.ts +15 -0
- package/corpus/templates/content/actions/submit-content-database-form.ts +7 -0
- package/corpus/templates/content/actions/sync-local-folder-source.ts +14 -0
- package/corpus/templates/content/actions/update-content-database-view.ts +1 -0
- package/corpus/templates/content/actions/update-content-sidebar-state.ts +27 -0
- package/corpus/templates/content/actions/update-document.ts +158 -66
- package/corpus/templates/content/app/components/EmptyState.tsx +4 -57
- package/corpus/templates/content/app/components/editor/CommentsSidebar.tsx +8 -1
- package/corpus/templates/content/app/components/editor/DocumentEditor.tsx +519 -178
- package/corpus/templates/content/app/components/editor/DocumentInfoPanel.tsx +39 -0
- package/corpus/templates/content/app/components/editor/DocumentProperties.tsx +1 -1
- package/corpus/templates/content/app/components/editor/DocumentToolbar.tsx +266 -7
- package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +430 -152
- package/corpus/templates/content/app/components/editor/database/sidebar.tsx +467 -66
- package/corpus/templates/content/app/components/editor/database/view-config.ts +9 -3
- package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +720 -196
- package/corpus/templates/content/app/components/sidebar/DocumentTreeItem.tsx +173 -1
- package/corpus/templates/content/app/components/sidebar/document-sidebar-sections.ts +1 -1
- package/corpus/templates/content/app/components/sidebar/select-content-space.ts +91 -16
- package/corpus/templates/content/app/entry.client.tsx +5 -1
- package/corpus/templates/content/app/hooks/use-content-database.ts +84 -3
- package/corpus/templates/content/app/hooks/use-content-spaces.ts +60 -2
- package/corpus/templates/content/app/hooks/use-create-page.ts +30 -0
- package/corpus/templates/content/app/hooks/use-documents.ts +270 -19
- package/corpus/templates/content/app/i18n-data.ts +243 -20
- package/corpus/templates/content/app/lib/local-folder-picker-safety.ts +54 -0
- package/corpus/templates/content/app/lib/local-folder-picker-support.ts +18 -0
- package/corpus/templates/content/app/routes/_app.favorites.tsx +30 -0
- package/corpus/templates/content/app/routes/_app.local-files.tsx +18 -6
- package/corpus/templates/content/changelog/2026-07-17-workspace-files-now-stay-in-a-loading-state-until-automatic-.md +6 -0
- package/corpus/templates/content/changelog/2026-07-17-workspace-switching-now-opens-the-selected-files-database-pr.md +6 -0
- package/corpus/templates/content/changelog/2026-07-17-workspaces-now-expand-above-their-own-files-list-without-dup.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-create-named-workspaces-each-with-its-own-private-files-data.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-favorites-align-with-workspace-and-file-rows-in-the-sidebar.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-local-folder-selection-no-longer-invokes-the-unsafe-native-p.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-made-content-workspaces-independently-expandable-restored-or.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-page-details-now-live-in-a-shared-info-and-comments-rail-dat.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-workspace-database-views-now-control-sidebar-workspace-navig.md +6 -0
- package/corpus/templates/content/changelog/2026-07-18-workspace-navigation-now-aligns-favorites-with-workspace-pag.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-favorites-now-open-as-a-table-and-compact-breadcrumbs-make-w.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-files-databases-now-start-unfiltered-sidebar-rows-exactly-fo.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-sidebar-page-trees-now-open-only-when-expanded-remember-thei.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-workspace-file-databases-now-use-the-workspace-name-open-as-.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-workspace-navigation-now-stays-stable-on-hover-uses-folder-i.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-workspace-rows-now-use-folder-icons-and-deleting-a-user-crea.md +6 -0
- package/corpus/templates/content/changelog/2026-07-19-workspaces-can-be-created-without-leaving-the-workspaces-dat.md +6 -0
- package/corpus/templates/content/e2e/global-setup.ts +3 -2
- package/corpus/templates/content/parity/matrix.md +28 -28
- package/corpus/templates/content/parity/matrix.ts +8 -2
- package/corpus/templates/content/server/db/index.ts +1 -0
- package/corpus/templates/content/server/db/schema.ts +10 -0
- package/corpus/templates/content/server/lib/documents.ts +12 -7
- package/corpus/templates/content/server/plugins/db.ts +17 -0
- package/corpus/templates/content/shared/api.ts +9 -0
- package/corpus/templates/content/shared/database-form.ts +11 -2
- package/corpus/templates/content/vite.config.ts +1 -0
- package/corpus/templates/design/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/design/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/dispatch/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/dispatch/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/forms/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/forms/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/macros/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/mail/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/mail/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/plan/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/plan/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/slides/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/slides/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/tasks/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/templates/tasks/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/tasks/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/toolkit/CHANGELOG.md +6 -0
- package/corpus/toolkit/agent-native.eject.json +411 -0
- package/corpus/toolkit/package.json +5 -2
- package/dist/cli/eject.d.ts +21 -0
- package/dist/cli/eject.d.ts.map +1 -0
- package/dist/cli/eject.js +1145 -0
- package/dist/cli/eject.js.map +1 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/client/build-compatibility.d.ts +11 -0
- package/dist/client/build-compatibility.d.ts.map +1 -0
- package/dist/client/build-compatibility.js +56 -0
- package/dist/client/build-compatibility.js.map +1 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/resources/McpConnectionSuggestion.d.ts +4 -3
- package/dist/client/resources/McpConnectionSuggestion.d.ts.map +1 -1
- package/dist/client/resources/McpConnectionSuggestion.js +3 -3
- package/dist/client/resources/McpConnectionSuggestion.js.map +1 -1
- package/dist/client/resources/McpIntegrationDialog.d.ts +4 -3
- package/dist/client/resources/McpIntegrationDialog.d.ts.map +1 -1
- package/dist/client/resources/McpIntegrationDialog.js +2 -2
- package/dist/client/resources/McpIntegrationDialog.js.map +1 -1
- package/dist/client/resources/ResourcesPanel.d.ts +4 -1
- package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
- package/dist/client/resources/ResourcesPanel.js +9 -7
- package/dist/client/resources/ResourcesPanel.js.map +1 -1
- package/dist/client/resources/index.d.ts +3 -0
- package/dist/client/resources/index.d.ts.map +1 -1
- package/dist/client/resources/index.js +3 -0
- package/dist/client/resources/index.js.map +1 -1
- package/dist/client/resources/mcp-integration-catalog.d.ts +2 -1
- package/dist/client/resources/mcp-integration-catalog.d.ts.map +1 -1
- package/dist/client/resources/mcp-integration-catalog.js +6 -2
- package/dist/client/resources/mcp-integration-catalog.js.map +1 -1
- package/dist/client/resources/runtime.d.ts +2 -0
- package/dist/client/resources/runtime.d.ts.map +1 -0
- package/dist/client/resources/runtime.js +2 -0
- package/dist/client/resources/runtime.js.map +1 -0
- package/dist/client/route-chunk-recovery/index.d.ts +1 -0
- package/dist/client/route-chunk-recovery/index.d.ts.map +1 -1
- package/dist/client/route-chunk-recovery/index.js +1 -0
- package/dist/client/route-chunk-recovery/index.js.map +1 -1
- package/dist/client/setup-connections/catalog.d.ts +2 -0
- package/dist/client/setup-connections/catalog.d.ts.map +1 -0
- package/dist/client/setup-connections/catalog.js +7 -0
- package/dist/client/setup-connections/catalog.js.map +1 -0
- package/dist/client/setup-connections/index.d.ts +1 -0
- package/dist/client/setup-connections/index.d.ts.map +1 -1
- package/dist/client/setup-connections/index.js +1 -0
- package/dist/client/setup-connections/index.js.map +1 -1
- package/dist/client/setup-connections/runtime.d.ts +2 -0
- package/dist/client/setup-connections/runtime.d.ts.map +1 -0
- package/dist/client/setup-connections/runtime.js +2 -0
- package/dist/client/setup-connections/runtime.js.map +1 -0
- package/dist/client/use-action.d.ts.map +1 -1
- package/dist/client/use-action.js +19 -1
- package/dist/client/use-action.js.map +1 -1
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/awareness.d.ts.map +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/connections/catalog.d.ts +5 -3
- package/dist/connections/catalog.d.ts.map +1 -1
- package/dist/connections/catalog.js +16 -8
- package/dist/connections/catalog.js.map +1 -1
- package/dist/connections/index.d.ts +1 -1
- package/dist/connections/index.d.ts.map +1 -1
- package/dist/connections/index.js +1 -1
- package/dist/connections/index.js.map +1 -1
- package/dist/connections/runtime.d.ts +2 -0
- package/dist/connections/runtime.d.ts.map +1 -0
- package/dist/connections/runtime.js +2 -0
- package/dist/connections/runtime.js.map +1 -0
- package/dist/deploy/build.js +2 -1
- package/dist/deploy/build.js.map +1 -1
- package/dist/eject/provider-api-definitions.d.ts +34 -0
- package/dist/eject/provider-api-definitions.d.ts.map +1 -0
- package/dist/eject/provider-api-definitions.js +88 -0
- package/dist/eject/provider-api-definitions.js.map +1 -0
- package/dist/eject/remote-mcp-presets.d.ts +17 -0
- package/dist/eject/remote-mcp-presets.d.ts.map +1 -0
- package/dist/eject/remote-mcp-presets.js +81 -0
- package/dist/eject/remote-mcp-presets.js.map +1 -0
- package/dist/eject/setup-readiness-ui.d.ts +7 -0
- package/dist/eject/setup-readiness-ui.d.ts.map +1 -0
- package/dist/eject/setup-readiness-ui.js +13 -0
- package/dist/eject/setup-readiness-ui.js.map +1 -0
- package/dist/eject/workspace-connections.d.ts +11 -0
- package/dist/eject/workspace-connections.d.ts.map +1 -0
- package/dist/eject/workspace-connections.js +47 -0
- package/dist/eject/workspace-connections.js.map +1 -0
- package/dist/file-upload/actions/upload-image.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/adapter-overrides.d.ts +3 -0
- package/dist/integrations/adapter-overrides.d.ts.map +1 -0
- package/dist/integrations/adapter-overrides.js +7 -0
- package/dist/integrations/adapter-overrides.js.map +1 -0
- package/dist/integrations/eject/messaging-adapters.d.ts +12 -0
- package/dist/integrations/eject/messaging-adapters.d.ts.map +1 -0
- package/dist/integrations/eject/messaging-adapters.js +49 -0
- package/dist/integrations/eject/messaging-adapters.js.map +1 -0
- package/dist/integrations/index.d.ts +3 -2
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/index.js +2 -1
- package/dist/integrations/index.js.map +1 -1
- package/dist/integrations/plugin.d.ts +32 -1
- package/dist/integrations/plugin.d.ts.map +1 -1
- package/dist/integrations/plugin.js +19 -12
- package/dist/integrations/plugin.js.map +1 -1
- package/dist/integrations/runtime.d.ts +2 -0
- package/dist/integrations/runtime.d.ts.map +1 -0
- package/dist/integrations/runtime.js +2 -0
- package/dist/integrations/runtime.js.map +1 -0
- package/dist/integrations/types.d.ts +3 -1
- package/dist/integrations/types.d.ts.map +1 -1
- package/dist/integrations/types.js.map +1 -1
- package/dist/notifications/routes.d.ts +2 -2
- package/dist/observability/routes.d.ts +5 -5
- package/dist/org/context.d.ts +4 -2
- package/dist/org/context.d.ts.map +1 -1
- package/dist/org/context.js +44 -22
- package/dist/org/context.js.map +1 -1
- package/dist/package-lifecycle/eject-manifest.d.ts +43 -0
- package/dist/package-lifecycle/eject-manifest.d.ts.map +1 -0
- package/dist/package-lifecycle/eject-manifest.js +219 -0
- package/dist/package-lifecycle/eject-manifest.js.map +1 -0
- package/dist/package-lifecycle/index.d.ts +1 -0
- package/dist/package-lifecycle/index.d.ts.map +1 -1
- package/dist/package-lifecycle/index.js +1 -0
- package/dist/package-lifecycle/index.js.map +1 -1
- package/dist/provider-api/actions/custom-provider-registration.d.ts +11 -11
- package/dist/provider-api/actions/provider-api.d.ts +11 -11
- package/dist/provider-api/index.d.ts +6 -2
- package/dist/provider-api/index.d.ts.map +1 -1
- package/dist/provider-api/index.js +25 -12
- package/dist/provider-api/index.js.map +1 -1
- package/dist/provider-api/runtime.d.ts +2 -0
- package/dist/provider-api/runtime.d.ts.map +1 -0
- package/dist/provider-api/runtime.js +2 -0
- package/dist/provider-api/runtime.js.map +1 -0
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/server/action-routes.d.ts.map +1 -1
- package/dist/server/action-routes.js +32 -2
- package/dist/server/action-routes.js.map +1 -1
- package/dist/server/auth-plugin.d.ts.map +1 -1
- package/dist/server/auth-plugin.js +9 -5
- package/dist/server/auth-plugin.js.map +1 -1
- package/dist/server/better-auth-instance.d.ts.map +1 -1
- package/dist/server/better-auth-instance.js +4 -1
- package/dist/server/better-auth-instance.js.map +1 -1
- package/dist/setup-connections/index.d.ts +1 -1
- package/dist/setup-connections/index.d.ts.map +1 -1
- package/dist/setup-connections/index.js +1 -1
- package/dist/setup-connections/index.js.map +1 -1
- package/dist/shared/mcp-embed-headers.d.ts +1 -1
- package/dist/shared/mcp-embed-headers.d.ts.map +1 -1
- package/dist/shared/mcp-embed-headers.js +1 -1
- package/dist/shared/mcp-embed-headers.js.map +1 -1
- package/dist/shared/merge-by-id.d.ts +5 -0
- package/dist/shared/merge-by-id.d.ts.map +1 -0
- package/dist/shared/merge-by-id.js +7 -0
- package/dist/shared/merge-by-id.js.map +1 -0
- package/dist/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/dist/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/dist/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/dist/templates/chat/AGENTS.md +3 -2
- package/dist/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/dist/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/dist/templates/default/AGENTS.md +6 -5
- package/dist/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/dist/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/dist/templates/headless/AGENTS.md +5 -4
- package/dist/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/dist/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
- package/dist/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/dist/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/dist/templates/workspace-core/AGENTS.md +4 -4
- package/dist/templates/workspace-root/AGENTS.md +4 -4
- package/dist/vite/client.d.ts +6 -0
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +30 -2
- package/dist/vite/client.js.map +1 -1
- package/docs/content/agent-native-toolkit.mdx +38 -0
- package/docs/content/package-lifecycle.mdx +54 -4
- package/package.json +15 -2
- package/src/a2a/agent-card.ts +83 -0
- package/src/a2a/artifact-response.ts +1648 -0
- package/src/a2a/auth-policy.ts +66 -0
- package/src/a2a/caller-auth.ts +102 -0
- package/src/a2a/client.ts +876 -0
- package/src/a2a/correlation.ts +50 -0
- package/src/a2a/handlers.ts +1285 -0
- package/src/a2a/index.ts +50 -0
- package/src/a2a/invoke.ts +348 -0
- package/src/a2a/response-text.ts +53 -0
- package/src/a2a/server.ts +586 -0
- package/src/a2a/task-store.ts +917 -0
- package/src/a2a/types.ts +221 -0
- package/src/a2a-claims.ts +52 -0
- package/src/action-change-marker.ts +74 -0
- package/src/action-ui.ts +38 -0
- package/src/action.ts +1406 -0
- package/src/adapters/cli/index.ts +6 -0
- package/src/adapters/cli/registry.ts +73 -0
- package/src/adapters/cli/shell-adapter.ts +92 -0
- package/src/adapters/cli/types.ts +27 -0
- package/src/agent/action-continuation-guidance.ts +38 -0
- package/src/agent/app-model-defaults.ts +201 -0
- package/src/agent/context-xray/actions/context-evict.ts +56 -0
- package/src/agent/context-xray/actions/context-manifest-get.ts +75 -0
- package/src/agent/context-xray/actions/context-pin.ts +56 -0
- package/src/agent/context-xray/actions/context-preview-get.ts +134 -0
- package/src/agent/context-xray/actions/context-report.ts +75 -0
- package/src/agent/context-xray/actions/context-restore.ts +51 -0
- package/src/agent/context-xray/actions/errors.ts +40 -0
- package/src/agent/context-xray/apply-directives.ts +137 -0
- package/src/agent/context-xray/directives-store.ts +178 -0
- package/src/agent/context-xray/identity.ts +37 -0
- package/src/agent/context-xray/manifest.ts +284 -0
- package/src/agent/context-xray/migrations.ts +32 -0
- package/src/agent/context-xray/plugin.ts +23 -0
- package/src/agent/context-xray/schema.ts +17 -0
- package/src/agent/context-xray/segments.ts +194 -0
- package/src/agent/context-xray/tokenize.ts +93 -0
- package/src/agent/default-model.ts +5 -0
- package/src/agent/durable-background.ts +547 -0
- package/src/agent/engine/ai-sdk-engine.ts +565 -0
- package/src/agent/engine/anthropic-engine.ts +320 -0
- package/src/agent/engine/builder-engine.ts +1110 -0
- package/src/agent/engine/builder-gateway-headers.ts +44 -0
- package/src/agent/engine/builtin.ts +122 -0
- package/src/agent/engine/context-directives-transform.ts +73 -0
- package/src/agent/engine/continuation-dispatch-retry.ts +168 -0
- package/src/agent/engine/credential-errors.ts +69 -0
- package/src/agent/engine/index.ts +54 -0
- package/src/agent/engine/openai-compatible-endpoint.ts +25 -0
- package/src/agent/engine/output-tokens.ts +181 -0
- package/src/agent/engine/provider-env-vars.ts +69 -0
- package/src/agent/engine/registry.ts +853 -0
- package/src/agent/engine/tool-call-journal-seed.ts +85 -0
- package/src/agent/engine/translate-ai-sdk.ts +407 -0
- package/src/agent/engine/translate-anthropic.ts +611 -0
- package/src/agent/engine/types.ts +310 -0
- package/src/agent/harness/acp-adapter.ts +893 -0
- package/src/agent/harness/acp-builtin.ts +70 -0
- package/src/agent/harness/ai-sdk-adapter.ts +509 -0
- package/src/agent/harness/background.ts +365 -0
- package/src/agent/harness/builtin.ts +50 -0
- package/src/agent/harness/index.ts +86 -0
- package/src/agent/harness/lifecycle.ts +498 -0
- package/src/agent/harness/registry.ts +97 -0
- package/src/agent/harness/runner.ts +182 -0
- package/src/agent/harness/store.ts +466 -0
- package/src/agent/harness/translate.ts +130 -0
- package/src/agent/harness/types.ts +129 -0
- package/src/agent/index.ts +32 -0
- package/src/agent/loop-settings.ts +186 -0
- package/src/agent/model-config.ts +363 -0
- package/src/agent/observational-memory/compactor.ts +78 -0
- package/src/agent/observational-memory/config.ts +78 -0
- package/src/agent/observational-memory/index.ts +79 -0
- package/src/agent/observational-memory/internal-run.ts +89 -0
- package/src/agent/observational-memory/message-text.ts +49 -0
- package/src/agent/observational-memory/migrations.ts +44 -0
- package/src/agent/observational-memory/observer.ts +128 -0
- package/src/agent/observational-memory/plugin.ts +35 -0
- package/src/agent/observational-memory/prompts.ts +53 -0
- package/src/agent/observational-memory/read.ts +131 -0
- package/src/agent/observational-memory/reflector.ts +119 -0
- package/src/agent/observational-memory/schema.ts +48 -0
- package/src/agent/observational-memory/store.ts +275 -0
- package/src/agent/observational-memory/types.ts +65 -0
- package/src/agent/processors.ts +209 -0
- package/src/agent/production-agent.ts +8254 -0
- package/src/agent/run-loop-with-resume.ts +394 -0
- package/src/agent/run-manager.ts +1825 -0
- package/src/agent/run-ownership.ts +75 -0
- package/src/agent/run-store.ts +2601 -0
- package/src/agent/runtime-context.ts +169 -0
- package/src/agent/thread-data-builder.ts +1584 -0
- package/src/agent/tool-call-journal.ts +368 -0
- package/src/agent/tool-error-redaction.ts +52 -0
- package/src/agent/tool-result-images.ts +178 -0
- package/src/agent/tool-search.ts +376 -0
- package/src/agent/types.ts +372 -0
- package/src/agent-native/index.ts +198 -0
- package/src/agent-web/config.ts +253 -0
- package/src/agent-web/generator.ts +382 -0
- package/src/agent-web/index.ts +36 -0
- package/src/appearance/actions/change-appearance.ts +35 -0
- package/src/application-state/emitter.ts +81 -0
- package/src/application-state/handlers.ts +121 -0
- package/src/application-state/index.ts +44 -0
- package/src/application-state/script-helpers.ts +155 -0
- package/src/application-state/store.ts +274 -0
- package/src/assets/branding/agent-native.icon/Assets/background.svg +3 -0
- package/src/assets/branding/agent-native.icon/Assets/foreground.svg +12 -0
- package/src/assets/branding/agent-native.icon/icon.json +49 -0
- package/src/assets/branding/favicon.png +0 -0
- package/src/assets/branding/favicon.svg +1 -0
- package/src/assets/branding/icon-on-dark.svg +10 -0
- package/src/assets/branding/icon-on-light.svg +10 -0
- package/src/assets/branding/mac-app-icon.svg +1 -0
- package/src/assets/branding/slack-bot/agent-native-1024.png +0 -0
- package/src/assets/branding/slack-bot/agent-native-512.png +0 -0
- package/src/assets/branding/tray-icon.svg +6 -0
- package/src/assets/branding/wordmark-on-dark.svg +21 -0
- package/src/assets/branding/wordmark-on-light.svg +21 -0
- package/src/assets/fonts/LICENSE_LIBERATION +96 -0
- package/src/assets/fonts/LICENSE_NOTO_NASKH_ARABIC +93 -0
- package/src/assets/fonts/LiberationSans-Bold.ttf +0 -0
- package/src/assets/fonts/LiberationSans-Regular.ttf +0 -0
- package/src/assets/fonts/NotoNaskhArabic-Variable.ttf +0 -0
- package/src/audit/actions/export-audit-events.ts +162 -0
- package/src/audit/actions/get-audit-event.ts +24 -0
- package/src/audit/actions/list-audit-events.ts +66 -0
- package/src/audit/cleanup-job.ts +100 -0
- package/src/audit/config.ts +90 -0
- package/src/audit/index.ts +43 -0
- package/src/audit/record.ts +180 -0
- package/src/audit/redact.ts +109 -0
- package/src/audit/store.ts +346 -0
- package/src/audit/types.ts +141 -0
- package/src/automation/index.ts +802 -0
- package/src/brand-kit/brand-signals.ts +124 -0
- package/src/brand-kit/fig/index.ts +64 -0
- package/src/brand-kit/index.ts +72 -0
- package/src/brand-kit/types.ts +113 -0
- package/src/browser-sessions/actions.ts +302 -0
- package/src/browser-sessions/routes.ts +234 -0
- package/src/browser-sessions/store.ts +679 -0
- package/src/browser-sessions/types.ts +84 -0
- package/src/changelog/parse.ts +328 -0
- package/src/chat-threads/emitter.ts +22 -0
- package/src/chat-threads/schema.ts +43 -0
- package/src/chat-threads/store.ts +1311 -0
- package/src/checkpoints/index.ts +15 -0
- package/src/checkpoints/service.ts +142 -0
- package/src/checkpoints/store.ts +153 -0
- package/src/cli/add.ts +425 -0
- package/src/cli/agent.ts +424 -0
- package/src/cli/agents.ts +122 -0
- package/src/cli/app-skill.ts +1455 -0
- package/src/cli/atomic-json-file.ts +324 -0
- package/src/cli/audit-agent-web.ts +324 -0
- package/src/cli/changelog.ts +199 -0
- package/src/cli/claude-code-participant.ts +515 -0
- package/src/cli/code-agent-commands.ts +270 -0
- package/src/cli/code-agent-connector.ts +1109 -0
- package/src/cli/code-agent-executor.ts +1970 -0
- package/src/cli/code-agent-output-smoother.ts +140 -0
- package/src/cli/code-agent-runs.concurrent-worker.ts +33 -0
- package/src/cli/code-agent-runs.ts +548 -0
- package/src/cli/code.ts +1805 -0
- package/src/cli/codex-cli-participant.ts +496 -0
- package/src/cli/connect.ts +2714 -0
- package/src/cli/content-local.ts +442 -0
- package/src/cli/context-xray-local.ts +2193 -0
- package/src/cli/create-workspace.ts +30 -0
- package/src/cli/create.ts +2247 -0
- package/src/cli/deploy-build.ts +50 -0
- package/src/cli/design-connect.ts +3187 -0
- package/src/cli/doctor.ts +472 -0
- package/src/cli/eject.ts +1594 -0
- package/src/cli/eval.ts +134 -0
- package/src/cli/gateway-helpers.ts +70 -0
- package/src/cli/index.ts +1217 -0
- package/src/cli/info.ts +105 -0
- package/src/cli/invoke.ts +288 -0
- package/src/cli/mcp-config-writers.ts +857 -0
- package/src/cli/mcp.ts +594 -0
- package/src/cli/migrate.ts +1813 -0
- package/src/cli/migration-codemod.ts +646 -0
- package/src/cli/multi-frontier-runs.ts +1952 -0
- package/src/cli/package-lifecycle.ts +823 -0
- package/src/cli/plan-blocks.ts +143 -0
- package/src/cli/plan-local.ts +3189 -0
- package/src/cli/plan-publish-store.ts +138 -0
- package/src/cli/pr-visual-recap-workflow.ts +2 -0
- package/src/cli/recap.ts +5 -0
- package/src/cli/setup-agents.ts +120 -0
- package/src/cli/skills-content/assets-skill.ts +83 -0
- package/src/cli/skills-content/canvas.ts +153 -0
- package/src/cli/skills-content/connection.ts +52 -0
- package/src/cli/skills-content/content-skill.ts +120 -0
- package/src/cli/skills-content/design-exploration-skill.ts +118 -0
- package/src/cli/skills-content/design-visual-edit-skill.ts +228 -0
- package/src/cli/skills-content/document-quality.ts +196 -0
- package/src/cli/skills-content/exemplar.ts +69 -0
- package/src/cli/skills-content/help.ts +77 -0
- package/src/cli/skills-content/index.ts +22 -0
- package/src/cli/skills-content/local-files.ts +100 -0
- package/src/cli/skills-content/plan-setup-auth.ts +80 -0
- package/src/cli/skills-content/visual-plan-skill.ts +493 -0
- package/src/cli/skills-content/visual-recap-skill.ts +553 -0
- package/src/cli/skills-content/visualize-repo-skill.ts +93 -0
- package/src/cli/skills-content/wireframe.ts +349 -0
- package/src/cli/skills.ts +4340 -0
- package/src/cli/sync-builder-starter-manifest.ts +631 -0
- package/src/cli/telemetry.ts +136 -0
- package/src/cli/templates-meta.ts +269 -0
- package/src/cli/upgrade.ts +956 -0
- package/src/cli/visualize-repo.ts +715 -0
- package/src/cli/workspace-dev.ts +1486 -0
- package/src/cli/workspacify.ts +258 -0
- package/src/client/AgentAskPopover.tsx +89 -0
- package/src/client/AgentChatHome.tsx +66 -0
- package/src/client/AgentNative.tsx +161 -0
- package/src/client/AgentNativeEmbedded.tsx +288 -0
- package/src/client/AgentNativeFrame.tsx +151 -0
- package/src/client/AgentPanel.tsx +3437 -0
- package/src/client/AgentTaskCard.tsx +273 -0
- package/src/client/AppearancePicker.tsx +79 -0
- package/src/client/AssistantChat.tsx +5793 -0
- package/src/client/ClientOnly.tsx +22 -0
- package/src/client/CommandMenu.tsx +726 -0
- package/src/client/ConnectBuilderCard.tsx +390 -0
- package/src/client/DefaultSpinner.tsx +47 -0
- package/src/client/ErrorBoundary.tsx +359 -0
- package/src/client/ErrorReportActions.tsx +69 -0
- package/src/client/FeedbackButton.tsx +553 -0
- package/src/client/HighlightedCodeBlock.tsx +173 -0
- package/src/client/IframeEmbed.tsx +151 -0
- package/src/client/KeepTabOpenNotice.tsx +181 -0
- package/src/client/MultiTabAssistantChat.tsx +2576 -0
- package/src/client/NewWorkspaceAppFlow.tsx +525 -0
- package/src/client/PoweredByBadge.tsx +284 -0
- package/src/client/RunStuckBanner.tsx +431 -0
- package/src/client/StarfieldBackground.tsx +466 -0
- package/src/client/Turnstile.tsx +125 -0
- package/src/client/active-run-state.ts +139 -0
- package/src/client/agent-chat/index.ts +279 -0
- package/src/client/agent-chat-adapter.ts +3692 -0
- package/src/client/agent-chat.ts +1233 -0
- package/src/client/agent-engine-key.ts +122 -0
- package/src/client/agent-page/AgentContextTab.tsx +487 -0
- package/src/client/agent-page/AgentEmptyState.tsx +44 -0
- package/src/client/agent-page/AgentJobsTab.tsx +441 -0
- package/src/client/agent-page/AgentTabFrame.tsx +39 -0
- package/src/client/agent-page/AgentTabsPage.tsx +1096 -0
- package/src/client/agent-page/types.ts +18 -0
- package/src/client/agent-page/use-jobs.ts +150 -0
- package/src/client/agent-sidebar-state.ts +166 -0
- package/src/client/analytics/index.ts +40 -0
- package/src/client/analytics-session.ts +70 -0
- package/src/client/analytics.ts +1757 -0
- package/src/client/api-path.ts +124 -0
- package/src/client/app-providers.tsx +230 -0
- package/src/client/appearance.ts +130 -0
- package/src/client/application-state.ts +154 -0
- package/src/client/assistant-ui-recovery.tsx +205 -0
- package/src/client/automation/index.ts +4 -0
- package/src/client/automation.ts +22 -0
- package/src/client/blocks/AiEditableField.tsx +30 -0
- package/src/client/blocks/BlockView.tsx +145 -0
- package/src/client/blocks/RegistryBlockDataProvider.tsx +121 -0
- package/src/client/blocks/SchemaBlockEditor.tsx +457 -0
- package/src/client/blocks/agent.ts +95 -0
- package/src/client/blocks/code-block-direction.ts +21 -0
- package/src/client/blocks/index.ts +308 -0
- package/src/client/blocks/library/AnnotatedCodeBlock.tsx +710 -0
- package/src/client/blocks/library/ApiEndpointBlock.tsx +1120 -0
- package/src/client/blocks/library/DataModelBlock.tsx +775 -0
- package/src/client/blocks/library/DiffBlock.tsx +1854 -0
- package/src/client/blocks/library/FileTreeBlock.tsx +868 -0
- package/src/client/blocks/library/HighlightedCode.tsx +260 -0
- package/src/client/blocks/library/JsonExplorerBlock.tsx +608 -0
- package/src/client/blocks/library/MermaidBlock.tsx +362 -0
- package/src/client/blocks/library/OpenApiSpecBlock.tsx +998 -0
- package/src/client/blocks/library/annotated-code.config.ts +101 -0
- package/src/client/blocks/library/annotation-rail.tsx +1020 -0
- package/src/client/blocks/library/api-endpoint.config.ts +207 -0
- package/src/client/blocks/library/block-copy.ts +399 -0
- package/src/client/blocks/library/callout.config.ts +57 -0
- package/src/client/blocks/library/callout.tsx +149 -0
- package/src/client/blocks/library/checklist.config.ts +56 -0
- package/src/client/blocks/library/checklist.tsx +208 -0
- package/src/client/blocks/library/code-filename-label.tsx +59 -0
- package/src/client/blocks/library/code-highlight.tsx +178 -0
- package/src/client/blocks/library/code-tabs.config.ts +70 -0
- package/src/client/blocks/library/code-tabs.tsx +606 -0
- package/src/client/blocks/library/code.config.ts +69 -0
- package/src/client/blocks/library/code.tsx +440 -0
- package/src/client/blocks/library/columns.config.ts +85 -0
- package/src/client/blocks/library/columns.tsx +334 -0
- package/src/client/blocks/library/data-model.config.ts +152 -0
- package/src/client/blocks/library/dev-doc-ui.tsx +191 -0
- package/src/client/blocks/library/diagram.config.ts +222 -0
- package/src/client/blocks/library/diagram.tsx +958 -0
- package/src/client/blocks/library/diff.config.ts +115 -0
- package/src/client/blocks/library/file-tree.config.ts +92 -0
- package/src/client/blocks/library/html.config.ts +79 -0
- package/src/client/blocks/library/html.tsx +258 -0
- package/src/client/blocks/library/json-explorer.config.ts +74 -0
- package/src/client/blocks/library/mermaid.config.ts +49 -0
- package/src/client/blocks/library/narrow-container.tsx +37 -0
- package/src/client/blocks/library/openapi-spec.config.ts +66 -0
- package/src/client/blocks/library/question-form.config.ts +127 -0
- package/src/client/blocks/library/question-form.tsx +944 -0
- package/src/client/blocks/library/sanitize-html.ts +343 -0
- package/src/client/blocks/library/server-specs.ts +338 -0
- package/src/client/blocks/library/specs.tsx +308 -0
- package/src/client/blocks/library/table.config.ts +61 -0
- package/src/client/blocks/library/table.tsx +449 -0
- package/src/client/blocks/library/tabs.config.ts +96 -0
- package/src/client/blocks/library/tabs.tsx +665 -0
- package/src/client/blocks/library/wireframe-icons.ts +210 -0
- package/src/client/blocks/library/wireframe-kit.tsx +1850 -0
- package/src/client/blocks/library/wireframe.config.ts +539 -0
- package/src/client/blocks/library/wireframe.tsx +535 -0
- package/src/client/blocks/mdx.ts +364 -0
- package/src/client/blocks/provider.tsx +51 -0
- package/src/client/blocks/registry.ts +83 -0
- package/src/client/blocks/schema-form/introspect.ts +201 -0
- package/src/client/blocks/server.ts +170 -0
- package/src/client/blocks/types.ts +415 -0
- package/src/client/browser-session-bridge.ts +548 -0
- package/src/client/browser-tab-id.ts +36 -0
- package/src/client/build-compatibility.ts +77 -0
- package/src/client/builder-frame.ts +194 -0
- package/src/client/builder-mark.tsx +21 -0
- package/src/client/changelog/Changelog.tsx +333 -0
- package/src/client/changelog/index.ts +1 -0
- package/src/client/chat/ChatHistoryList.tsx +7 -0
- package/src/client/chat/attachment-adapters.ts +426 -0
- package/src/client/chat/connectors.ts +1579 -0
- package/src/client/chat/index.ts +160 -0
- package/src/client/chat/markdown-renderer.tsx +693 -0
- package/src/client/chat/message-components.tsx +1326 -0
- package/src/client/chat/repo-helpers.ts +281 -0
- package/src/client/chat/run-recovery.tsx +994 -0
- package/src/client/chat/runtime.ts +1810 -0
- package/src/client/chat/tool-call-display.tsx +1270 -0
- package/src/client/chat/tool-render-registry.tsx +144 -0
- package/src/client/chat/use-agent-chat-lifecycle-tracking.ts +74 -0
- package/src/client/chat/use-reconnect-reader-owner.ts +28 -0
- package/src/client/chat/widgets/DataChartRenderer.tsx +242 -0
- package/src/client/chat/widgets/DataChartWidget.tsx +51 -0
- package/src/client/chat/widgets/DataInsightsWidget.tsx +59 -0
- package/src/client/chat/widgets/DataTableWidget.tsx +240 -0
- package/src/client/chat/widgets/InlineExtensionWidget.tsx +60 -0
- package/src/client/chat/widgets/builtin-tool-renderers.tsx +213 -0
- package/src/client/chat/widgets/data-widget-types.ts +1 -0
- package/src/client/chat/widgets/inline-extension-result.ts +86 -0
- package/src/client/chat-model-groups.ts +171 -0
- package/src/client/chat-thread-url.ts +11 -0
- package/src/client/chat-view-transition.ts +213 -0
- package/src/client/client-action.ts +21 -0
- package/src/client/client-bootstrap.ts +7 -0
- package/src/client/client-surface.ts +41 -0
- package/src/client/clipboard.ts +89 -0
- package/src/client/code-agent-chat-adapter.ts +537 -0
- package/src/client/collab/index.ts +60 -0
- package/src/client/command-navigation/index.ts +15 -0
- package/src/client/comments-review/index.ts +1 -0
- package/src/client/components/AgentPresenceChip.tsx +4 -0
- package/src/client/components/ApiKeySettings.tsx +309 -0
- package/src/client/components/CodeAgentIndicator.tsx +59 -0
- package/src/client/components/CodeRequiredDialog.tsx +470 -0
- package/src/client/components/LiveCursorOverlay.tsx +5 -0
- package/src/client/components/MissingKeyCard.tsx +61 -0
- package/src/client/components/PresenceBar.tsx +4 -0
- package/src/client/components/RecentEditHighlights.tsx +4 -0
- package/src/client/components/RemoteSelectionRings.tsx +5 -0
- package/src/client/components/icons/AgentNativeIcon.tsx +46 -0
- package/src/client/components/ui/dialog.tsx +1 -0
- package/src/client/components/ui/dropdown-menu.tsx +1 -0
- package/src/client/components/ui/hover-card.tsx +1 -0
- package/src/client/components/ui/message-scroller.tsx +131 -0
- package/src/client/components/ui/popover.tsx +1 -0
- package/src/client/components/ui/sheet.tsx +1 -0
- package/src/client/components/ui/tooltip.tsx +1 -0
- package/src/client/composer/index.ts +11 -0
- package/src/client/composer/runtime-adapters.tsx +123 -0
- package/src/client/composer/use-mention-search.ts +7 -0
- package/src/client/composer/wired-components.tsx +53 -0
- package/src/client/context-xray/ContextMeter.tsx +124 -0
- package/src/client/context-xray/ContextSegmentRow.tsx +27 -0
- package/src/client/context-xray/ContextTreemap.tsx +24 -0
- package/src/client/context-xray/ContextXRayPanel.tsx +59 -0
- package/src/client/context-xray/SegmentProvenancePopover.tsx +18 -0
- package/src/client/context-xray/format.ts +27 -0
- package/src/client/conversation/AgentConversation.tsx +555 -0
- package/src/client/conversation/code-agent-transcript.ts +283 -0
- package/src/client/conversation/index.ts +22 -0
- package/src/client/conversation/types.ts +85 -0
- package/src/client/conversation/use-near-bottom-autoscroll.ts +278 -0
- package/src/client/create-query-client.ts +86 -0
- package/src/client/db-admin/DataGrid.tsx +551 -0
- package/src/client/db-admin/DbAdminPage.tsx +218 -0
- package/src/client/db-admin/DevDatabaseLink.tsx +16 -0
- package/src/client/db-admin/EditableCell.tsx +451 -0
- package/src/client/db-admin/FilterBar.tsx +203 -0
- package/src/client/db-admin/ResultsGrid.tsx +114 -0
- package/src/client/db-admin/RowSidePanel.tsx +337 -0
- package/src/client/db-admin/SqlEditor.tsx +840 -0
- package/src/client/db-admin/TableBrowser.tsx +212 -0
- package/src/client/db-admin/TableEditor.tsx +760 -0
- package/src/client/db-admin/cell-format.ts +246 -0
- package/src/client/db-admin/changeset.ts +296 -0
- package/src/client/db-admin/export-utils.ts +78 -0
- package/src/client/db-admin/index.ts +33 -0
- package/src/client/db-admin/sql-storage.ts +134 -0
- package/src/client/db-admin/storage.ts +68 -0
- package/src/client/db-admin/useAgentSync.ts +226 -0
- package/src/client/db-admin/useDbAdmin.ts +294 -0
- package/src/client/dev-overlay/DevOverlay.tsx +576 -0
- package/src/client/dev-overlay/builtins.ts +40 -0
- package/src/client/dev-overlay/index.ts +23 -0
- package/src/client/dev-overlay/registry.ts +67 -0
- package/src/client/dev-overlay/types.ts +64 -0
- package/src/client/dev-overlay/use-dev-option.ts +78 -0
- package/src/client/dev-overlay/use-dev-overlay-shortcut.ts +31 -0
- package/src/client/dynamic-suggestions.ts +455 -0
- package/src/client/embed-auth.ts +544 -0
- package/src/client/embed.ts +54 -0
- package/src/client/error-capture.ts +690 -0
- package/src/client/error-format.ts +211 -0
- package/src/client/error-reporting.ts +100 -0
- package/src/client/extensions/AgentNativeExtensionFrame.e2e-host.tsx +136 -0
- package/src/client/extensions/AgentNativeExtensionFrame.tsx +708 -0
- package/src/client/extensions/EmbeddedExtension.tsx +604 -0
- package/src/client/extensions/ExtensionEditor.tsx +450 -0
- package/src/client/extensions/ExtensionQueryErrorState.tsx +47 -0
- package/src/client/extensions/ExtensionSlot.tsx +345 -0
- package/src/client/extensions/ExtensionViewer.tsx +1502 -0
- package/src/client/extensions/ExtensionViewerPage.tsx +32 -0
- package/src/client/extensions/ExtensionsListPage.tsx +432 -0
- package/src/client/extensions/ExtensionsSidebarSection.tsx +1259 -0
- package/src/client/extensions/InlineExtensionFrame.tsx +660 -0
- package/src/client/extensions/agent-native-extension-runtime.ts +495 -0
- package/src/client/extensions/delete-extension.ts +76 -0
- package/src/client/extensions/extension-load-error.ts +26 -0
- package/src/client/extensions/extension-order.ts +49 -0
- package/src/client/extensions/extension-popularity.ts +61 -0
- package/src/client/extensions/iframe-bridge.ts +377 -0
- package/src/client/extensions/index.ts +84 -0
- package/src/client/extensions/portable-extension.ts +712 -0
- package/src/client/feature-flags/FeatureFlagsPanel.tsx +519 -0
- package/src/client/feature-flags/helpers.ts +77 -0
- package/src/client/feature-flags/index.ts +13 -0
- package/src/client/feature-flags/types.ts +29 -0
- package/src/client/feature-flags/use-feature-flag.ts +26 -0
- package/src/client/feedback-context.ts +90 -0
- package/src/client/frame-protocol.ts +168 -0
- package/src/client/frame.ts +329 -0
- package/src/client/guided-questions.tsx +1152 -0
- package/src/client/history/VersionHistoryPanel.tsx +175 -0
- package/src/client/history/index.ts +21 -0
- package/src/client/history/use-history.ts +114 -0
- package/src/client/hooks/index.ts +46 -0
- package/src/client/host/index.ts +170 -0
- package/src/client/host-bridge.ts +1272 -0
- package/src/client/host-tools.ts +190 -0
- package/src/client/i18n.tsx +798 -0
- package/src/client/index.ts +370 -0
- package/src/client/integrations/IntegrationCard.tsx +186 -0
- package/src/client/integrations/IntegrationsPanel.tsx +633 -0
- package/src/client/integrations/api.ts +295 -0
- package/src/client/integrations/index.ts +29 -0
- package/src/client/integrations/useIntegrationStatus.ts +52 -0
- package/src/client/mcp-app-host.ts +720 -0
- package/src/client/mcp-apps/McpAppRenderer.tsx +760 -0
- package/src/client/navigation/index.ts +54 -0
- package/src/client/notifications/NotificationsBell.tsx +383 -0
- package/src/client/notifications/index.ts +1 -0
- package/src/client/observability/ObservabilityDashboard.tsx +890 -0
- package/src/client/observability/ThumbsFeedback.tsx +160 -0
- package/src/client/observability/index.ts +20 -0
- package/src/client/observability/useObservability.ts +266 -0
- package/src/client/onboarding/OnboardingBanner.tsx +73 -0
- package/src/client/onboarding/OnboardingPanel.tsx +1036 -0
- package/src/client/onboarding/SetupButton.tsx +64 -0
- package/src/client/onboarding/index.ts +25 -0
- package/src/client/onboarding/use-onboarding.ts +164 -0
- package/src/client/onboarding/use-preview-mode.ts +40 -0
- package/src/client/org/InvitationBanner.tsx +148 -0
- package/src/client/org/OrgSwitcher.tsx +754 -0
- package/src/client/org/RequireActiveOrg.tsx +337 -0
- package/src/client/org/TeamPage.tsx +1432 -0
- package/src/client/org/hooks.ts +359 -0
- package/src/client/org/index.ts +70 -0
- package/src/client/org/workspace-app-links.ts +367 -0
- package/src/client/org-team/index.ts +1 -0
- package/src/client/progress/RunsTray.tsx +680 -0
- package/src/client/progress/index.ts +1 -0
- package/src/client/require-session.tsx +142 -0
- package/src/client/resources/BuiltinCapabilityDetail.tsx +258 -0
- package/src/client/resources/McpConnectionSuggestion.tsx +276 -0
- package/src/client/resources/McpIntegrationDialog.tsx +808 -0
- package/src/client/resources/McpServerDetail.tsx +230 -0
- package/src/client/resources/ResourceEditor.tsx +872 -0
- package/src/client/resources/ResourceTree.tsx +860 -0
- package/src/client/resources/ResourcesPanel.tsx +1960 -0
- package/src/client/resources/index.ts +25 -0
- package/src/client/resources/mcp-integration-catalog.ts +771 -0
- package/src/client/resources/mcp-integration-logos.ts +108 -0
- package/src/client/resources/runtime.ts +1 -0
- package/src/client/resources/use-builtin-capabilities.ts +113 -0
- package/src/client/resources/use-mcp-servers.ts +217 -0
- package/src/client/resources/use-resources.ts +402 -0
- package/src/client/review/ReviewCommentComposer.tsx +123 -0
- package/src/client/review/ReviewStatusBadge.tsx +39 -0
- package/src/client/review/ReviewThreadPanel.tsx +625 -0
- package/src/client/review/index.ts +38 -0
- package/src/client/review/use-review.ts +186 -0
- package/src/client/route-chunk-recovery/index.ts +2 -0
- package/src/client/route-chunk-recovery.ts +331 -0
- package/src/client/route-state.ts +455 -0
- package/src/client/route-warmup.tsx +543 -0
- package/src/client/session-replay-iframe.e2e-host.tsx +100 -0
- package/src/client/session-replay.ts +3417 -0
- package/src/client/settings/AgentsSection.tsx +441 -0
- package/src/client/settings/AutomationsSection.tsx +516 -0
- package/src/client/settings/BackgroundAgentSection.tsx +189 -0
- package/src/client/settings/BrowserSection.tsx +110 -0
- package/src/client/settings/DemoModeSection.tsx +48 -0
- package/src/client/settings/SecretsSection.tsx +875 -0
- package/src/client/settings/SettingsPanel.tsx +3162 -0
- package/src/client/settings/SettingsSection.tsx +283 -0
- package/src/client/settings/SettingsTabsPage.tsx +592 -0
- package/src/client/settings/UsageSection.tsx +401 -0
- package/src/client/settings/VoiceTranscriptionSection.tsx +960 -0
- package/src/client/settings/agent-settings-search.ts +220 -0
- package/src/client/settings/index.ts +27 -0
- package/src/client/settings/useBuilderStatus.ts +1055 -0
- package/src/client/setup-connections/BuilderConnectCard.tsx +89 -0
- package/src/client/setup-connections/ProviderReadinessBadge.tsx +73 -0
- package/src/client/setup-connections/SetupConnectionsPage.tsx +94 -0
- package/src/client/setup-connections/catalog.ts +6 -0
- package/src/client/setup-connections/index.ts +47 -0
- package/src/client/setup-connections/runtime.ts +1 -0
- package/src/client/sharing/ShareButton.tsx +1748 -0
- package/src/client/sharing/ShareDialog.tsx +846 -0
- package/src/client/sharing/VisibilityBadge.tsx +4 -0
- package/src/client/sharing/index.ts +2 -0
- package/src/client/sse-event-processor.ts +2002 -0
- package/src/client/terminal/AgentTerminal.tsx +488 -0
- package/src/client/terminal/index.ts +7 -0
- package/src/client/theme.ts +27 -0
- package/src/client/tombstone/agent-presence-chip.ts +17 -0
- package/src/client/tombstone/editor.ts +265 -0
- package/src/client/tombstone/live-cursor-overlay.ts +21 -0
- package/src/client/tombstone/presence-bar.ts +17 -0
- package/src/client/tombstone/recent-edit-highlights.ts +17 -0
- package/src/client/tombstone/remote-selection-rings.ts +21 -0
- package/src/client/tombstone/rich-markdown-editor.ts +265 -0
- package/src/client/tombstone/ui-dialog.ts +49 -0
- package/src/client/tombstone/ui-dropdown-menu.ts +69 -0
- package/src/client/tombstone/ui-hover-card.ts +21 -0
- package/src/client/tombstone/ui-popover.ts +25 -0
- package/src/client/tombstone/ui-sheet.ts +49 -0
- package/src/client/tombstone/ui-tooltip.ts +29 -0
- package/src/client/tombstone/visual-style-controls.ts +61 -0
- package/src/client/tool-cells/BashCell.tsx +164 -0
- package/src/client/tool-cells/EditCell.tsx +303 -0
- package/src/client/tool-cells/FilesChangedSummary.tsx +208 -0
- package/src/client/tool-cells/WriteCell.tsx +145 -0
- package/src/client/tool-cells/index.ts +7 -0
- package/src/client/tool-display.ts +41 -0
- package/src/client/track.ts +57 -0
- package/src/client/transcription/BuilderTranscriptionCta.tsx +120 -0
- package/src/client/transcription/use-live-transcription.ts +292 -0
- package/src/client/ui/index.ts +55 -0
- package/src/client/uploads/index.ts +6 -0
- package/src/client/uploads/upload-editor-image.ts +79 -0
- package/src/client/uploads/use-upload-resource.ts +24 -0
- package/src/client/url-scrub.ts +51 -0
- package/src/client/use-action.ts +797 -0
- package/src/client/use-agent-chat-context.ts +63 -0
- package/src/client/use-agent-chat-home-handoff.ts +207 -0
- package/src/client/use-agent-chat.ts +53 -0
- package/src/client/use-agent-engine-configured.ts +211 -0
- package/src/client/use-avatar.ts +127 -0
- package/src/client/use-change-version.ts +150 -0
- package/src/client/use-chat-models.ts +252 -0
- package/src/client/use-chat-threads.ts +1262 -0
- package/src/client/use-db-sync.ts +1112 -0
- package/src/client/use-demo-mode-status.ts +30 -0
- package/src/client/use-dev-mode.ts +177 -0
- package/src/client/use-external-value.ts +40 -0
- package/src/client/use-pausing-interval.ts +65 -0
- package/src/client/use-pinch-zoom.ts +202 -0
- package/src/client/use-run-stuck-detection.ts +427 -0
- package/src/client/use-send-to-agent-chat.ts +85 -0
- package/src/client/use-session.ts +114 -0
- package/src/client/utils.ts +7 -0
- package/src/client/visual-style-controls.tsx +1 -0
- package/src/client/vite-dev-recovery-script.ts +226 -0
- package/src/client/voice-provider-status.ts +44 -0
- package/src/client/widgets/index.ts +41 -0
- package/src/code-agents/background-controller.ts +398 -0
- package/src/code-agents/background-run.ts +156 -0
- package/src/code-agents/index.ts +95 -0
- package/src/code-agents/prompt-attachments.ts +39 -0
- package/src/code-agents/transcript-normalizer.ts +750 -0
- package/src/code-agents/transcript-order.ts +73 -0
- package/src/coding-tools/index.ts +742 -0
- package/src/coding-tools/run-code.ts +1662 -0
- package/src/coding-tools/sandbox/adapter.ts +82 -0
- package/src/coding-tools/sandbox/background.ts +406 -0
- package/src/coding-tools/sandbox/executions-store.ts +517 -0
- package/src/coding-tools/sandbox/index.ts +132 -0
- package/src/coding-tools/sandbox/local-child-process-adapter.ts +217 -0
- package/src/collab/agent-identity.ts +5 -0
- package/src/collab/agent-presence.ts +341 -0
- package/src/collab/awareness-store.ts +196 -0
- package/src/collab/awareness.ts +317 -0
- package/src/collab/client-struct.ts +366 -0
- package/src/collab/client.ts +1205 -0
- package/src/collab/emitter.ts +31 -0
- package/src/collab/follow-mode.ts +107 -0
- package/src/collab/index.ts +151 -0
- package/src/collab/json-to-yjs.ts +504 -0
- package/src/collab/presence.ts +207 -0
- package/src/collab/recent-edits.ts +215 -0
- package/src/collab/routes.ts +191 -0
- package/src/collab/storage.ts +228 -0
- package/src/collab/struct-routes.ts +133 -0
- package/src/collab/text-to-yjs.ts +79 -0
- package/src/collab/undo.ts +432 -0
- package/src/collab/xml-ops.ts +68 -0
- package/src/collab/ydoc-manager.ts +544 -0
- package/src/command-navigation/actions.ts +100 -0
- package/src/command-navigation/index.ts +12 -0
- package/src/comments-review/index.ts +1 -0
- package/src/connections/catalog.ts +451 -0
- package/src/connections/index.ts +48 -0
- package/src/connections/reader.ts +911 -0
- package/src/connections/runtime.ts +1 -0
- package/src/credentials/index.ts +187 -0
- package/src/data-programs/actions.ts +335 -0
- package/src/data-programs/contract.ts +284 -0
- package/src/data-programs/execute.ts +693 -0
- package/src/data-programs/index.ts +72 -0
- package/src/data-programs/schema.ts +148 -0
- package/src/data-programs/store.ts +755 -0
- package/src/data-widgets/index.ts +376 -0
- package/src/db/client.ts +1627 -0
- package/src/db/create-get-db.ts +579 -0
- package/src/db/ddl-guard.ts +302 -0
- package/src/db/drizzle-config.ts +190 -0
- package/src/db/ensure-additive-columns.ts +430 -0
- package/src/db/index.ts +57 -0
- package/src/db/migrations.ts +691 -0
- package/src/db/request-telemetry.ts +154 -0
- package/src/db/runtime-diagnostics.ts +331 -0
- package/src/db/schema.ts +121 -0
- package/src/db/widen-columns.ts +75 -0
- package/src/db-admin/agent-tools.ts +202 -0
- package/src/db-admin/index.ts +26 -0
- package/src/db-admin/operations.ts +803 -0
- package/src/db-admin/routes.ts +174 -0
- package/src/db-admin/types.ts +110 -0
- package/src/demo/browser-state.ts +47 -0
- package/src/demo/fetch-interceptor.ts +175 -0
- package/src/demo/redact.ts +575 -0
- package/src/deploy/build.ts +3938 -0
- package/src/deploy/immutable-assets.ts +65 -0
- package/src/deploy/route-discovery.ts +458 -0
- package/src/deploy/workspace-core.ts +282 -0
- package/src/deploy/workspace-deploy.ts +1488 -0
- package/src/eject/provider-api-definitions.ts +193 -0
- package/src/eject/remote-mcp-presets.ts +137 -0
- package/src/eject/setup-readiness-ui.tsx +29 -0
- package/src/eject/workspace-connections.ts +92 -0
- package/src/embedding/agent.ts +159 -0
- package/src/embedding/bridge.ts +297 -0
- package/src/embedding/index.ts +43 -0
- package/src/embedding/protocol.ts +185 -0
- package/src/embedding/react.tsx +319 -0
- package/src/embeddings/index.ts +233 -0
- package/src/eval/agent-runner.ts +210 -0
- package/src/eval/define-eval.ts +55 -0
- package/src/eval/index.ts +49 -0
- package/src/eval/report.ts +75 -0
- package/src/eval/runner.ts +369 -0
- package/src/eval/scorer.ts +244 -0
- package/src/eval/types.ts +188 -0
- package/src/event-bus/bus.ts +140 -0
- package/src/event-bus/index.ts +3 -0
- package/src/event-bus/registry.ts +79 -0
- package/src/event-bus/types.ts +29 -0
- package/src/extensions/actions.ts +1636 -0
- package/src/extensions/change-marker.ts +54 -0
- package/src/extensions/content-patch.ts +468 -0
- package/src/extensions/fetch-tool.ts +461 -0
- package/src/extensions/html-shell.ts +803 -0
- package/src/extensions/local.ts +462 -0
- package/src/extensions/path.ts +40 -0
- package/src/extensions/proxy-security.ts +171 -0
- package/src/extensions/routes.ts +1080 -0
- package/src/extensions/schema.ts +269 -0
- package/src/extensions/session-replay-iframe.ts +131 -0
- package/src/extensions/slots/routes.ts +126 -0
- package/src/extensions/slots/schema.ts +87 -0
- package/src/extensions/slots/store.ts +450 -0
- package/src/extensions/store.ts +1347 -0
- package/src/extensions/theme.ts +114 -0
- package/src/extensions/url-safety.ts +316 -0
- package/src/extensions/web-content.ts +663 -0
- package/src/extensions/web-search-tool.ts +437 -0
- package/src/feature-flags/a2a-action-route.ts +56 -0
- package/src/feature-flags/actions/get-feature-flags.ts +24 -0
- package/src/feature-flags/actions/list-feature-flags.ts +69 -0
- package/src/feature-flags/actions/set-feature-flag.ts +89 -0
- package/src/feature-flags/index.ts +21 -0
- package/src/feature-flags/permissions.ts +53 -0
- package/src/feature-flags/plugin.ts +44 -0
- package/src/feature-flags/registry.ts +96 -0
- package/src/feature-flags/store.ts +176 -0
- package/src/file-upload/actions/upload-image.ts +213 -0
- package/src/file-upload/builder.ts +431 -0
- package/src/file-upload/index.ts +24 -0
- package/src/file-upload/pre-upload-attachments.ts +305 -0
- package/src/file-upload/registry.ts +125 -0
- package/src/file-upload/types.ts +89 -0
- package/src/guards/db-tool-scoping.ts +129 -0
- package/src/guards/index.ts +23 -0
- package/src/guards/no-drizzle-push.ts +116 -0
- package/src/guards/no-env-credentials.ts +229 -0
- package/src/guards/no-env-mutation.ts +114 -0
- package/src/guards/no-localhost-fallback.ts +124 -0
- package/src/guards/no-unscoped-credentials.ts +227 -0
- package/src/guards/no-unscoped-queries.ts +834 -0
- package/src/guards/scan-utils.ts +105 -0
- package/src/guards/types.ts +30 -0
- package/src/history/actions/create-resource-version.ts +92 -0
- package/src/history/actions/get-resource-version.ts +60 -0
- package/src/history/actions/list-resource-history.ts +53 -0
- package/src/history/actions/list-resource-versions.ts +43 -0
- package/src/history/actions/restore-resource-version.ts +96 -0
- package/src/history/index.ts +26 -0
- package/src/history/registry.ts +111 -0
- package/src/history/store.ts +379 -0
- package/src/history/types.ts +69 -0
- package/src/index.browser.ts +155 -0
- package/src/index.ts +408 -0
- package/src/ingestion/docx.ts +158 -0
- package/src/ingestion/figma-node-to-html.ts +1860 -0
- package/src/ingestion/figma.ts +548 -0
- package/src/ingestion/index.ts +107 -0
- package/src/ingestion/media.ts +264 -0
- package/src/ingestion/notion.ts +121 -0
- package/src/ingestion/office.ts +213 -0
- package/src/ingestion/orchestration.ts +160 -0
- package/src/ingestion/pptx.ts +331 -0
- package/src/ingestion/selection.ts +81 -0
- package/src/ingestion/website.ts +151 -0
- package/src/integrations/a2a-continuation-marker.ts +2 -0
- package/src/integrations/a2a-continuation-processor.ts +888 -0
- package/src/integrations/a2a-continuations-store.ts +643 -0
- package/src/integrations/adapter-overrides.ts +12 -0
- package/src/integrations/adapters/discord.ts +364 -0
- package/src/integrations/adapters/email.ts +1164 -0
- package/src/integrations/adapters/google-docs.ts +371 -0
- package/src/integrations/adapters/index.ts +29 -0
- package/src/integrations/adapters/microsoft-teams.ts +413 -0
- package/src/integrations/adapters/slack.ts +1914 -0
- package/src/integrations/adapters/telegram.ts +386 -0
- package/src/integrations/adapters/whatsapp.ts +358 -0
- package/src/integrations/awaiting-input-store.ts +130 -0
- package/src/integrations/catalog.ts +571 -0
- package/src/integrations/computer-supervision-store.ts +423 -0
- package/src/integrations/computer-supervision.ts +213 -0
- package/src/integrations/config-store.ts +131 -0
- package/src/integrations/controls-store.ts +187 -0
- package/src/integrations/eject/messaging-adapters.ts +85 -0
- package/src/integrations/google-docs-poller.ts +671 -0
- package/src/integrations/identity-links-store.ts +210 -0
- package/src/integrations/identity.ts +196 -0
- package/src/integrations/index.ts +220 -0
- package/src/integrations/installations-store.ts +677 -0
- package/src/integrations/integration-memory.ts +187 -0
- package/src/integrations/internal-token.ts +106 -0
- package/src/integrations/pending-tasks-retry-job.ts +286 -0
- package/src/integrations/pending-tasks-store.ts +468 -0
- package/src/integrations/plugin.ts +3048 -0
- package/src/integrations/remote-commands-store.ts +690 -0
- package/src/integrations/remote-devices-store.ts +492 -0
- package/src/integrations/remote-json-safety.ts +127 -0
- package/src/integrations/remote-push-delivery-job.ts +48 -0
- package/src/integrations/remote-push-delivery.ts +370 -0
- package/src/integrations/remote-push-store.ts +664 -0
- package/src/integrations/remote-retry-job.ts +55 -0
- package/src/integrations/remote-run-events-store.ts +222 -0
- package/src/integrations/remote-types.ts +186 -0
- package/src/integrations/runtime.ts +1 -0
- package/src/integrations/scope-store.ts +498 -0
- package/src/integrations/slack-manifest.ts +78 -0
- package/src/integrations/slack-oauth.ts +344 -0
- package/src/integrations/task-queue-stats.ts +144 -0
- package/src/integrations/thread-mapping-store.ts +134 -0
- package/src/integrations/types.ts +485 -0
- package/src/integrations/usage-budget-store.ts +906 -0
- package/src/integrations/webhook-delivery.ts +55 -0
- package/src/integrations/webhook-handler.ts +1939 -0
- package/src/jobs/actions/list-recurring-jobs.ts +105 -0
- package/src/jobs/actions/manage-recurring-job.ts +85 -0
- package/src/jobs/cron.ts +126 -0
- package/src/jobs/index.ts +9 -0
- package/src/jobs/scheduler.ts +703 -0
- package/src/jobs/tools.ts +367 -0
- package/src/local-artifacts/index.ts +1372 -0
- package/src/localization/actions/get-localization-preference.ts +24 -0
- package/src/localization/actions/set-localization-preference.ts +32 -0
- package/src/localization/default-messages.ts +1009 -0
- package/src/localization/index.ts +2 -0
- package/src/localization/server.ts +131 -0
- package/src/localization/shared.ts +208 -0
- package/src/mcp/actions/call-mcp-tool.ts +19 -0
- package/src/mcp/actions/create-org-service-token.ts +87 -0
- package/src/mcp/actions/list-mcp-tools.ts +18 -0
- package/src/mcp/actions/list-org-service-tokens.ts +44 -0
- package/src/mcp/actions/revoke-org-service-token.ts +30 -0
- package/src/mcp/actions/service-token-access.ts +121 -0
- package/src/mcp/ask-app-inline-tasks.ts +125 -0
- package/src/mcp/build-server.ts +2356 -0
- package/src/mcp/builtin-tools.ts +1506 -0
- package/src/mcp/connect-route.ts +1460 -0
- package/src/mcp/connect-store.ts +680 -0
- package/src/mcp/embed-app.ts +2051 -0
- package/src/mcp/embed-route.ts +84 -0
- package/src/mcp/external-agent-policy.ts +18 -0
- package/src/mcp/index.ts +47 -0
- package/src/mcp/oauth-route.ts +1016 -0
- package/src/mcp/oauth-store.ts +581 -0
- package/src/mcp/oauth-token.ts +227 -0
- package/src/mcp/org-directory.ts +343 -0
- package/src/mcp/route-paths.ts +34 -0
- package/src/mcp/screen-memory-stdio.ts +290 -0
- package/src/mcp/server.ts +507 -0
- package/src/mcp/stdio.ts +328 -0
- package/src/mcp/workspace-resolve.ts +261 -0
- package/src/mcp-client/app-api.ts +136 -0
- package/src/mcp-client/app-result.ts +64 -0
- package/src/mcp-client/builtin-capabilities.ts +146 -0
- package/src/mcp-client/builtin-store.ts +93 -0
- package/src/mcp-client/config.ts +281 -0
- package/src/mcp-client/errors.ts +54 -0
- package/src/mcp-client/hub-client.ts +172 -0
- package/src/mcp-client/hub-routes.ts +198 -0
- package/src/mcp-client/index.ts +504 -0
- package/src/mcp-client/manager.ts +968 -0
- package/src/mcp-client/oauth-client.ts +462 -0
- package/src/mcp-client/oauth-routes.ts +307 -0
- package/src/mcp-client/remote-store.ts +674 -0
- package/src/mcp-client/remote-url.ts +97 -0
- package/src/mcp-client/routes.ts +1093 -0
- package/src/mcp-client/screen-memory-local.ts +461 -0
- package/src/mcp-client/tool-policy.ts +182 -0
- package/src/mcp-client/visibility.ts +56 -0
- package/src/mcp-client/workspace-servers.ts +379 -0
- package/src/navigation/index.ts +170 -0
- package/src/notifications/actions.ts +151 -0
- package/src/notifications/channels.ts +410 -0
- package/src/notifications/index.ts +22 -0
- package/src/notifications/registry.ts +216 -0
- package/src/notifications/routes.ts +106 -0
- package/src/notifications/store.ts +236 -0
- package/src/notifications/types.ts +52 -0
- package/src/oauth-tokens/google-refresh.ts +175 -0
- package/src/oauth-tokens/index.ts +15 -0
- package/src/oauth-tokens/store.ts +384 -0
- package/src/observability/cleanup-job.ts +124 -0
- package/src/observability/evals.ts +507 -0
- package/src/observability/experiments.ts +359 -0
- package/src/observability/feedback.ts +332 -0
- package/src/observability/hosted-model-experiment.ts +118 -0
- package/src/observability/index.ts +62 -0
- package/src/observability/plugin.ts +31 -0
- package/src/observability/routes.ts +431 -0
- package/src/observability/sentiment.ts +261 -0
- package/src/observability/store.ts +1347 -0
- package/src/observability/traces.ts +789 -0
- package/src/observability/tracing.ts +157 -0
- package/src/observability/tracking-identity.ts +55 -0
- package/src/observability/types.ts +211 -0
- package/src/onboarding/default-steps.ts +428 -0
- package/src/onboarding/index.ts +22 -0
- package/src/onboarding/plugin.ts +262 -0
- package/src/onboarding/registry.ts +47 -0
- package/src/onboarding/types.ts +96 -0
- package/src/org/accept-pending.ts +98 -0
- package/src/org/auto-join-domain.ts +113 -0
- package/src/org/context.ts +640 -0
- package/src/org/free-email-providers.ts +124 -0
- package/src/org/handlers.ts +1153 -0
- package/src/org/index.ts +63 -0
- package/src/org/migrations.ts +105 -0
- package/src/org/permissions.ts +30 -0
- package/src/org/plugin.ts +255 -0
- package/src/org/schema.ts +28 -0
- package/src/org/types.ts +57 -0
- package/src/org-team/index.ts +1 -0
- package/src/package-lifecycle/deprecated-imports.ts +179 -0
- package/src/package-lifecycle/eject-manifest.ts +345 -0
- package/src/package-lifecycle/index.ts +7 -0
- package/src/package-lifecycle/manifest.ts +120 -0
- package/src/package-lifecycle/migration-manifest.ts +159 -0
- package/src/package-lifecycle/migration-message.ts +6 -0
- package/src/package-lifecycle/tombstone.ts +58 -0
- package/src/package-lifecycle/upgrade-error.ts +37 -0
- package/src/private-blob/index.ts +18 -0
- package/src/private-blob/registry.ts +242 -0
- package/src/private-blob/types.ts +55 -0
- package/src/progress/actions.ts +179 -0
- package/src/progress/index.ts +16 -0
- package/src/progress/registry.ts +127 -0
- package/src/progress/routes.ts +89 -0
- package/src/progress/store.ts +353 -0
- package/src/progress/types.ts +59 -0
- package/src/provider-api/actions/custom-provider-registration.ts +197 -0
- package/src/provider-api/actions/delete-staged-dataset.ts +5 -0
- package/src/provider-api/actions/github-repo-files.ts +266 -0
- package/src/provider-api/actions/list-staged-datasets.ts +5 -0
- package/src/provider-api/actions/provider-api-audit.ts +88 -0
- package/src/provider-api/actions/provider-api.ts +460 -0
- package/src/provider-api/actions/query-staged-dataset.ts +5 -0
- package/src/provider-api/actions/staged-datasets.ts +359 -0
- package/src/provider-api/corpus-jobs-store.ts +522 -0
- package/src/provider-api/corpus-jobs.ts +1817 -0
- package/src/provider-api/custom-registry.ts +456 -0
- package/src/provider-api/github-repo.ts +675 -0
- package/src/provider-api/gong.ts +108 -0
- package/src/provider-api/index.ts +5444 -0
- package/src/provider-api/quota-governor.ts +562 -0
- package/src/provider-api/runtime.ts +1 -0
- package/src/provider-api/staged-datasets-aggregate.ts +304 -0
- package/src/provider-api/staged-datasets-store.ts +441 -0
- package/src/provider-api/staging.ts +483 -0
- package/src/resources/agents.ts +65 -0
- package/src/resources/emitter.ts +54 -0
- package/src/resources/handlers.ts +728 -0
- package/src/resources/index.ts +4 -0
- package/src/resources/metadata.ts +252 -0
- package/src/resources/script-helpers.ts +160 -0
- package/src/resources/store.ts +1618 -0
- package/src/review/actions/consume-review-feedback.ts +48 -0
- package/src/review/actions/create-review-comment.ts +108 -0
- package/src/review/actions/delete-review-comment.ts +67 -0
- package/src/review/actions/get-review-feedback.ts +49 -0
- package/src/review/actions/list-review-comments.ts +87 -0
- package/src/review/actions/reply-review-comment.ts +118 -0
- package/src/review/actions/resolve-review-thread.ts +94 -0
- package/src/review/actions/send-review-thread-to-agent.ts +62 -0
- package/src/review/actions/set-review-status.ts +58 -0
- package/src/review/identity.ts +101 -0
- package/src/review/index.ts +45 -0
- package/src/review/mentions.ts +44 -0
- package/src/review/registry.ts +111 -0
- package/src/review/store.ts +997 -0
- package/src/review/types.ts +101 -0
- package/src/router/index.ts +24 -0
- package/src/scripts/agent-engines/list-agent-engines.ts +130 -0
- package/src/scripts/agent-engines/manage-agent-engine.ts +197 -0
- package/src/scripts/agent-engines/set-agent-engine.ts +84 -0
- package/src/scripts/agent-engines/test-agent-engine.ts +174 -0
- package/src/scripts/call-agent.ts +792 -0
- package/src/scripts/chat/index.ts +8 -0
- package/src/scripts/chat/open-chat.ts +56 -0
- package/src/scripts/chat/search-chats.ts +121 -0
- package/src/scripts/core-scripts.ts +22 -0
- package/src/scripts/db/check-scoping.ts +212 -0
- package/src/scripts/db/exec.ts +791 -0
- package/src/scripts/db/index.ts +19 -0
- package/src/scripts/db/migrate-encrypt-credentials.ts +223 -0
- package/src/scripts/db/migrate-encrypt-oauth-tokens.ts +213 -0
- package/src/scripts/db/migrate-user-api-keys.ts +257 -0
- package/src/scripts/db/patch.ts +820 -0
- package/src/scripts/db/query.ts +299 -0
- package/src/scripts/db/reset-dev-owner.ts +285 -0
- package/src/scripts/db/safety.ts +286 -0
- package/src/scripts/db/schema.ts +364 -0
- package/src/scripts/db/scoping.ts +341 -0
- package/src/scripts/db/sqlite-client.ts +78 -0
- package/src/scripts/db/tool-mode.ts +23 -0
- package/src/scripts/db/tool-schemas.ts +31 -0
- package/src/scripts/db/wipe-leaked-builder-keys.ts +201 -0
- package/src/scripts/dev/index.ts +296 -0
- package/src/scripts/dev/list-files.ts +119 -0
- package/src/scripts/dev/read-file.ts +77 -0
- package/src/scripts/dev/search-files.ts +151 -0
- package/src/scripts/dev/shell.ts +111 -0
- package/src/scripts/dev/write-file.ts +56 -0
- package/src/scripts/dev-session.ts +96 -0
- package/src/scripts/docs/index.ts +8 -0
- package/src/scripts/docs/search.ts +274 -0
- package/src/scripts/docs/source-search.ts +363 -0
- package/src/scripts/index.ts +15 -0
- package/src/scripts/manage-agent-loop-settings.ts +84 -0
- package/src/scripts/parse-args.ts +46 -0
- package/src/scripts/resources/delete-memory.ts +67 -0
- package/src/scripts/resources/delete.ts +69 -0
- package/src/scripts/resources/effective.ts +71 -0
- package/src/scripts/resources/index.ts +18 -0
- package/src/scripts/resources/list.ts +103 -0
- package/src/scripts/resources/migrate-learnings.ts +40 -0
- package/src/scripts/resources/read.ts +107 -0
- package/src/scripts/resources/save-memory.ts +99 -0
- package/src/scripts/resources/write.ts +158 -0
- package/src/scripts/runner.ts +339 -0
- package/src/scripts/utils.ts +130 -0
- package/src/search/index.ts +413 -0
- package/src/search-utils/index.ts +112 -0
- package/src/secrets/crypto.ts +228 -0
- package/src/secrets/index.ts +65 -0
- package/src/secrets/onboarding.ts +101 -0
- package/src/secrets/register-framework-secrets.ts +228 -0
- package/src/secrets/register.ts +129 -0
- package/src/secrets/routes.ts +697 -0
- package/src/secrets/schema.ts +52 -0
- package/src/secrets/storage.ts +561 -0
- package/src/secrets/substitution.ts +305 -0
- package/src/server/__snapshots__/agent-chat-plugin.surface.spec.ts.snap +150 -0
- package/src/server/action-change.ts +66 -0
- package/src/server/action-discovery.ts +774 -0
- package/src/server/action-routes.ts +658 -0
- package/src/server/agent-access.ts +72 -0
- package/src/server/agent-chat/action-filters-a2a.ts +339 -0
- package/src/server/agent-chat/browser-team-tools.ts +510 -0
- package/src/server/agent-chat/context-tools.ts +599 -0
- package/src/server/agent-chat/framework-prompts.ts +467 -0
- package/src/server/agent-chat/lazy-fs.ts +11 -0
- package/src/server/agent-chat/mcp-glue.ts +91 -0
- package/src/server/agent-chat/plugin-options.ts +379 -0
- package/src/server/agent-chat/process-run-failure.ts +62 -0
- package/src/server/agent-chat/prompt-resources.ts +1004 -0
- package/src/server/agent-chat/recurring-jobs-runtime.ts +80 -0
- package/src/server/agent-chat/request-surface.ts +71 -0
- package/src/server/agent-chat/run-code-tools.ts +67 -0
- package/src/server/agent-chat/script-entries.ts +796 -0
- package/src/server/agent-chat/shared-thread.ts +301 -0
- package/src/server/agent-chat/skill-frontmatter.ts +41 -0
- package/src/server/agent-chat-plugin.ts +5930 -0
- package/src/server/agent-discovery.ts +706 -0
- package/src/server/agent-engine-api-key-route.ts +236 -0
- package/src/server/agent-run-context.ts +204 -0
- package/src/server/agent-teams-run-queue.ts +344 -0
- package/src/server/agent-teams.ts +2257 -0
- package/src/server/agents-bundle.ts +464 -0
- package/src/server/analytics.ts +105 -0
- package/src/server/app-base-path.ts +79 -0
- package/src/server/app-name.ts +53 -0
- package/src/server/app-url.ts +184 -0
- package/src/server/attachment-actions.ts +276 -0
- package/src/server/attribution.ts +214 -0
- package/src/server/auth-marketing.ts +260 -0
- package/src/server/auth-plugin.ts +32 -0
- package/src/server/auth.ts +3803 -0
- package/src/server/better-auth-instance.ts +1201 -0
- package/src/server/builder-browser.ts +1701 -0
- package/src/server/builder-design-systems.ts +668 -0
- package/src/server/builder-space.ts +176 -0
- package/src/server/captcha.ts +63 -0
- package/src/server/capture-error.ts +64 -0
- package/src/server/cli-capture.ts +141 -0
- package/src/server/collab-plugin.ts +391 -0
- package/src/server/complete-text.ts +231 -0
- package/src/server/cookie-namespace.ts +159 -0
- package/src/server/core-routes-plugin.ts +4122 -0
- package/src/server/cors-origins.ts +60 -0
- package/src/server/create-server.ts +268 -0
- package/src/server/credential-provider.ts +1202 -0
- package/src/server/csrf.ts +229 -0
- package/src/server/date-utils.ts +42 -0
- package/src/server/deep-link.ts +119 -0
- package/src/server/derived-secret.ts +32 -0
- package/src/server/design-token-utils.ts +1032 -0
- package/src/server/desktop-sso.ts +83 -0
- package/src/server/edge.ts +69 -0
- package/src/server/email-actions.ts +218 -0
- package/src/server/email-template.ts +192 -0
- package/src/server/email-templates.ts +148 -0
- package/src/server/email.ts +219 -0
- package/src/server/embed-route.ts +283 -0
- package/src/server/embed-session.ts +805 -0
- package/src/server/embedded.ts +252 -0
- package/src/server/entry-server.tsx +154 -0
- package/src/server/framework-request-handler.ts +848 -0
- package/src/server/fusion-app.ts +447 -0
- package/src/server/google-auth-mode.ts +34 -0
- package/src/server/google-auth-plugin.ts +496 -0
- package/src/server/google-oauth-credentials.ts +128 -0
- package/src/server/google-oauth.ts +972 -0
- package/src/server/google-realtime-session.ts +182 -0
- package/src/server/h3-helpers.ts +174 -0
- package/src/server/http-response-telemetry.ts +396 -0
- package/src/server/identity-sso-store.ts +304 -0
- package/src/server/identity-sso.ts +514 -0
- package/src/server/index.ts +593 -0
- package/src/server/missing-key.ts +36 -0
- package/src/server/oauth-helpers.ts +44 -0
- package/src/server/oauth-public-origin.ts +44 -0
- package/src/server/oauth-return-url.ts +120 -0
- package/src/server/og-fonts-data.ts +15 -0
- package/src/server/og-fonts.ts +75 -0
- package/src/server/onboarding-html.ts +4040 -0
- package/src/server/open-route.ts +311 -0
- package/src/server/org-admin.ts +28 -0
- package/src/server/poll-events.ts +88 -0
- package/src/server/poll.ts +1224 -0
- package/src/server/prompts/framework-core-compact.ts +107 -0
- package/src/server/prompts/framework-core.ts +143 -0
- package/src/server/prompts/index.ts +16 -0
- package/src/server/prompts/model-overlays.ts +54 -0
- package/src/server/prompts/shared-rules.ts +104 -0
- package/src/server/realtime-voice.ts +967 -0
- package/src/server/recap-image-route.ts +242 -0
- package/src/server/recap-image-store.ts +185 -0
- package/src/server/request-context.ts +416 -0
- package/src/server/request-origin.ts +67 -0
- package/src/server/resources-plugin.ts +119 -0
- package/src/server/schema-prompt.ts +429 -0
- package/src/server/scoped-key-storage.ts +223 -0
- package/src/server/security-headers.ts +170 -0
- package/src/server/self-dispatch.ts +224 -0
- package/src/server/sentry-config.ts +73 -0
- package/src/server/sentry-plugin.ts +138 -0
- package/src/server/sentry.ts +444 -0
- package/src/server/short-lived-token.ts +170 -0
- package/src/server/social-og-image.ts +454 -0
- package/src/server/sse.ts +102 -0
- package/src/server/ssr-handler.ts +466 -0
- package/src/server/transcribe-voice.ts +1076 -0
- package/src/server/voice-providers-status.ts +118 -0
- package/src/server/workspace-oauth.ts +31 -0
- package/src/server/workspace-provider-oauth.ts +970 -0
- package/src/session-replay-iframe-protocol.ts +58 -0
- package/src/settings/handlers.ts +44 -0
- package/src/settings/index.ts +34 -0
- package/src/settings/org-settings.ts +83 -0
- package/src/settings/script-helpers.ts +24 -0
- package/src/settings/store.ts +247 -0
- package/src/settings/user-settings.ts +47 -0
- package/src/setup-connections/index.ts +90 -0
- package/src/setup-connections/onboarding.ts +47 -0
- package/src/shared/agent-access.ts +112 -0
- package/src/shared/agent-chat.ts +124 -0
- package/src/shared/agent-env.ts +46 -0
- package/src/shared/agent-readable-resource.ts +111 -0
- package/src/shared/agent-sidebar-url.ts +39 -0
- package/src/shared/cache-control.ts +25 -0
- package/src/shared/cloudflare-globals.d.ts +34 -0
- package/src/shared/context-xray.ts +172 -0
- package/src/shared/embed-auth.ts +6 -0
- package/src/shared/index.ts +83 -0
- package/src/shared/llm-connection.ts +42 -0
- package/src/shared/markdown-block-split.ts +129 -0
- package/src/shared/mcp-connect-content.ts +130 -0
- package/src/shared/mcp-embed-headers.ts +175 -0
- package/src/shared/mcp-integration-config.ts +101 -0
- package/src/shared/merge-by-id.ts +14 -0
- package/src/shared/oauth-state.ts +39 -0
- package/src/shared/reasoning-effort.ts +228 -0
- package/src/shared/route-warmup-config.ts +128 -0
- package/src/shared/runtime.ts +31 -0
- package/src/shared/social-meta.ts +82 -0
- package/src/shared/streaming-text-smoothing.ts +184 -0
- package/src/shared/truncate.ts +13 -0
- package/src/shared/workspace-app-audience.ts +177 -0
- package/src/shared/workspace-app-id.ts +54 -0
- package/src/sharing/access.ts +585 -0
- package/src/sharing/actions/create-agent-resource-link.ts +91 -0
- package/src/sharing/actions/extension-change.ts +22 -0
- package/src/sharing/actions/list-resource-shares.ts +93 -0
- package/src/sharing/actions/set-resource-visibility.ts +91 -0
- package/src/sharing/actions/share-resource.ts +322 -0
- package/src/sharing/actions/unshare-resource.ts +72 -0
- package/src/sharing/index.ts +35 -0
- package/src/sharing/registry.ts +201 -0
- package/src/sharing/schema.ts +99 -0
- package/src/styles/agent-conversation.css +766 -0
- package/src/styles/agent-native.css +938 -0
- package/src/styles/blocks.css +1717 -0
- package/src/styles/chat-history-list.css +1 -0
- package/src/styles/rich-markdown-editor.css +1 -0
- package/src/tailwind.preset.ts +140 -0
- package/src/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/src/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/src/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/src/templates/chat/AGENTS.md +3 -2
- package/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/src/templates/default/AGENTS.md +6 -5
- package/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/src/templates/headless/AGENTS.md +5 -4
- package/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
- package/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/src/templates/workspace-core/AGENTS.md +4 -4
- package/src/templates/workspace-root/AGENTS.md +4 -4
- package/src/terminal/cli-registry.ts +57 -0
- package/src/terminal/index.ts +22 -0
- package/src/terminal/pty-server.ts +389 -0
- package/src/terminal/terminal-plugin.ts +265 -0
- package/src/testing.ts +23 -0
- package/src/tracking/index.ts +10 -0
- package/src/tracking/providers.ts +422 -0
- package/src/tracking/registry.ts +102 -0
- package/src/tracking/route.ts +108 -0
- package/src/tracking/types.ts +16 -0
- package/src/transcription/builder-transcription.ts +118 -0
- package/src/triggers/actions/list-automations.ts +99 -0
- package/src/triggers/actions/manage-automation.ts +78 -0
- package/src/triggers/actions.ts +333 -0
- package/src/triggers/condition-evaluator.ts +163 -0
- package/src/triggers/dispatcher.ts +536 -0
- package/src/triggers/index.ts +13 -0
- package/src/triggers/routes.ts +322 -0
- package/src/triggers/types.ts +42 -0
- package/src/types/pglite.d.ts +26 -0
- package/src/usage/store.ts +698 -0
- package/src/vite/action-types-plugin.ts +481 -0
- package/src/vite/agent-web-plugin.ts +78 -0
- package/src/vite/agents-bundle-plugin.ts +185 -0
- package/src/vite/client.ts +3056 -0
- package/src/vite/index.ts +21 -0
- package/src/voice/index.ts +18 -0
- package/src/voice/voice-cleanup-prompt.ts +38 -0
- package/src/voice/voice-context.ts +217 -0
- package/src/voice/voice-replacements.ts +75 -0
- package/src/workspace-connections/credentials.ts +603 -0
- package/src/workspace-connections/index.ts +72 -0
- package/src/workspace-connections/lifecycle.ts +43 -0
- package/src/workspace-connections/store.ts +1943 -0
- package/src/workspace-files/index.ts +18 -0
- package/src/workspace-files/store.ts +339 -0
- package/src/workspace-files/tool.ts +266 -0
|
@@ -0,0 +1,1952 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
appendUniqueJsonLineAtomically,
|
|
6
|
+
withFileLockSync,
|
|
7
|
+
writeJsonFileAtomically,
|
|
8
|
+
writeTextFileAtomically,
|
|
9
|
+
} from "./atomic-json-file.js";
|
|
10
|
+
import { codeAgentStoreRoot } from "./code-agent-runs.js";
|
|
11
|
+
|
|
12
|
+
export type MultiFrontierPhase =
|
|
13
|
+
| "proposing"
|
|
14
|
+
| "cross_review"
|
|
15
|
+
| "converging"
|
|
16
|
+
| "awaiting_go"
|
|
17
|
+
| "implementing"
|
|
18
|
+
| "checkpoint_review"
|
|
19
|
+
| "paused"
|
|
20
|
+
| "completed"
|
|
21
|
+
| "failed"
|
|
22
|
+
| "canceled";
|
|
23
|
+
|
|
24
|
+
export type MultiFrontierParticipantRole = "driver" | "watchdog";
|
|
25
|
+
export type MultiFrontierParticipantPermission =
|
|
26
|
+
| "read_only"
|
|
27
|
+
| "workspace_write";
|
|
28
|
+
export type MultiFrontierParticipantStatus =
|
|
29
|
+
| "idle"
|
|
30
|
+
| "running"
|
|
31
|
+
| "waiting"
|
|
32
|
+
| "failed"
|
|
33
|
+
| "completed";
|
|
34
|
+
export type MultiFrontierApprovalState =
|
|
35
|
+
| "not_required"
|
|
36
|
+
| "pending"
|
|
37
|
+
| "approved"
|
|
38
|
+
| "rejected";
|
|
39
|
+
export type MultiFrontierRecoveryReason =
|
|
40
|
+
| "main_process_restarted"
|
|
41
|
+
| "driver_crashed"
|
|
42
|
+
| "watchdog_crashed"
|
|
43
|
+
| "app_quit"
|
|
44
|
+
| "canceled";
|
|
45
|
+
|
|
46
|
+
export interface MultiFrontierParticipantState {
|
|
47
|
+
participantId: string;
|
|
48
|
+
provider: string;
|
|
49
|
+
runtime: string;
|
|
50
|
+
model?: string;
|
|
51
|
+
capabilities?: string[];
|
|
52
|
+
sessionRef?: string;
|
|
53
|
+
role: MultiFrontierParticipantRole;
|
|
54
|
+
permission: MultiFrontierParticipantPermission;
|
|
55
|
+
status: MultiFrontierParticipantStatus;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface MultiFrontierDriverLease {
|
|
59
|
+
participantId: string;
|
|
60
|
+
generation: number;
|
|
61
|
+
leaseState: "inactive" | "active" | "revoked";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface MultiFrontierApproval {
|
|
65
|
+
state: MultiFrontierApprovalState;
|
|
66
|
+
proposalId?: string;
|
|
67
|
+
reviewPacketId?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface MultiFrontierRecovery {
|
|
71
|
+
reason: MultiFrontierRecoveryReason;
|
|
72
|
+
recoveredAt: string;
|
|
73
|
+
resumablePhase: MultiFrontierPhase;
|
|
74
|
+
checkpointId?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The durable state contract shared by the main process and every participant.
|
|
79
|
+
* Only the main-process coordinator writes it through this module.
|
|
80
|
+
*/
|
|
81
|
+
export interface MultiFrontierRunState {
|
|
82
|
+
schemaVersion: 1;
|
|
83
|
+
collaborationId: string;
|
|
84
|
+
/** Opaque local workspace handle; never a filesystem path. */
|
|
85
|
+
workspaceId?: string;
|
|
86
|
+
phase: MultiFrontierPhase;
|
|
87
|
+
participants: MultiFrontierParticipantState[];
|
|
88
|
+
driver: MultiFrontierDriverLease | null;
|
|
89
|
+
approval: MultiFrontierApproval;
|
|
90
|
+
checkpointIds: string[];
|
|
91
|
+
round: number;
|
|
92
|
+
proposalIds: string[];
|
|
93
|
+
reviewIds: string[];
|
|
94
|
+
/** Opt-in policy; explicit GO remains the durable default. */
|
|
95
|
+
autoContinueAfterAgreement: boolean;
|
|
96
|
+
recovery?: MultiFrontierRecovery;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface CreateMultiFrontierRunInput {
|
|
100
|
+
collaborationId: string;
|
|
101
|
+
workspaceId?: string;
|
|
102
|
+
phase?: MultiFrontierPhase;
|
|
103
|
+
participants: MultiFrontierParticipantState[];
|
|
104
|
+
approval?: MultiFrontierApproval;
|
|
105
|
+
checkpointIds?: string[];
|
|
106
|
+
autoContinueAfterAgreement?: boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface RecoverMultiFrontierRunInput {
|
|
110
|
+
now: string;
|
|
111
|
+
reason: MultiFrontierRecoveryReason;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface MultiFrontierParticipantEvent {
|
|
115
|
+
participantId: string;
|
|
116
|
+
generation?: number;
|
|
117
|
+
permission: MultiFrontierParticipantPermission;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface PersistedMultiFrontierParticipantEvent extends MultiFrontierParticipantEvent {
|
|
121
|
+
schemaVersion: 1;
|
|
122
|
+
id: string;
|
|
123
|
+
collaborationId: string;
|
|
124
|
+
createdAt: string;
|
|
125
|
+
status?: MultiFrontierParticipantStatus;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export type MultiFrontierArtifactKind = "proposal" | "review" | "checkpoint";
|
|
129
|
+
|
|
130
|
+
export interface MultiFrontierArtifactTestSummary {
|
|
131
|
+
name: string;
|
|
132
|
+
status: "passed" | "failed" | "skipped";
|
|
133
|
+
summary?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** A bounded, redacted projection used only for Desktop orchestrator recovery. */
|
|
137
|
+
export interface MultiFrontierOrchestrationArtifact {
|
|
138
|
+
id: string;
|
|
139
|
+
kind:
|
|
140
|
+
| "proposal"
|
|
141
|
+
| "cross_review"
|
|
142
|
+
| "revision"
|
|
143
|
+
| "synthesis"
|
|
144
|
+
| "checkpoint"
|
|
145
|
+
| "watchdog_review"
|
|
146
|
+
| "finding_disposition"
|
|
147
|
+
| "completion";
|
|
148
|
+
round: number;
|
|
149
|
+
participantId?: string;
|
|
150
|
+
text: string;
|
|
151
|
+
attribution: { participantIds: string[]; sourceArtifactIds: string[] };
|
|
152
|
+
supersedesArtifactId?: string;
|
|
153
|
+
metadata?: Record<string, unknown>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A deliberately narrow coordination record. Full diffs, transcripts, and
|
|
158
|
+
* provider payloads stay in their owning runtime rather than this durable
|
|
159
|
+
* cross-provider index.
|
|
160
|
+
*/
|
|
161
|
+
export interface PersistedMultiFrontierArtifact {
|
|
162
|
+
schemaVersion: 1;
|
|
163
|
+
id: string;
|
|
164
|
+
collaborationId: string;
|
|
165
|
+
kind: MultiFrontierArtifactKind;
|
|
166
|
+
createdAt: string;
|
|
167
|
+
participantId?: string;
|
|
168
|
+
title: string;
|
|
169
|
+
summary: string;
|
|
170
|
+
supersedesArtifactId?: string;
|
|
171
|
+
contentHash?: string;
|
|
172
|
+
fileRefs?: string[];
|
|
173
|
+
testSummary?: MultiFrontierArtifactTestSummary[];
|
|
174
|
+
orchestration?: MultiFrontierOrchestrationArtifact;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface AppendMultiFrontierArtifactInput {
|
|
178
|
+
id: string;
|
|
179
|
+
collaborationId: string;
|
|
180
|
+
kind: MultiFrontierArtifactKind;
|
|
181
|
+
createdAt?: string;
|
|
182
|
+
participantId?: string;
|
|
183
|
+
title: string;
|
|
184
|
+
summary: string;
|
|
185
|
+
supersedesArtifactId?: string;
|
|
186
|
+
contentHash?: string;
|
|
187
|
+
fileRefs?: string[];
|
|
188
|
+
testSummary?: MultiFrontierArtifactTestSummary[];
|
|
189
|
+
orchestration?: MultiFrontierOrchestrationArtifact;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface MultiFrontierParticipantEventRetention {
|
|
193
|
+
schemaVersion: 1;
|
|
194
|
+
retainedEventCount: number;
|
|
195
|
+
retainedByteCount: number;
|
|
196
|
+
droppedEventCount: number;
|
|
197
|
+
droppedByteCount: number;
|
|
198
|
+
truncated: boolean;
|
|
199
|
+
replay: {
|
|
200
|
+
requiresSnapshot: boolean;
|
|
201
|
+
firstRetainedEventId?: string;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface MultiFrontierParticipantEventRetentionLimits {
|
|
206
|
+
maxEventCount: number;
|
|
207
|
+
maxBytes: number;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface AppendMultiFrontierParticipantEventInput extends MultiFrontierParticipantEvent {
|
|
211
|
+
id: string;
|
|
212
|
+
collaborationId: string;
|
|
213
|
+
createdAt?: string;
|
|
214
|
+
status?: MultiFrontierParticipantStatus;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface MultiFrontierStoredRun extends MultiFrontierRunState {
|
|
218
|
+
createdAt: string;
|
|
219
|
+
updatedAt: string;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The desktop main-process coordinator is the sole caller of this transition
|
|
224
|
+
* boundary. Its callback receives a detached snapshot, never renderer input.
|
|
225
|
+
*/
|
|
226
|
+
export type MultiFrontierCoordinatorTransition = (
|
|
227
|
+
current: MultiFrontierStoredRun,
|
|
228
|
+
) => MultiFrontierRunState | MultiFrontierStoredRun | null;
|
|
229
|
+
|
|
230
|
+
export type AppendMultiFrontierParticipantEventResult =
|
|
231
|
+
| {
|
|
232
|
+
accepted: true;
|
|
233
|
+
deduplicated: boolean;
|
|
234
|
+
event: PersistedMultiFrontierParticipantEvent;
|
|
235
|
+
run: MultiFrontierStoredRun;
|
|
236
|
+
}
|
|
237
|
+
| {
|
|
238
|
+
accepted: false;
|
|
239
|
+
reason:
|
|
240
|
+
| "missing-run"
|
|
241
|
+
| "stale-driver"
|
|
242
|
+
| "missing-participant"
|
|
243
|
+
| "event-conflict"
|
|
244
|
+
| "terminal-participant";
|
|
245
|
+
run: MultiFrontierStoredRun | null;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export type AppendMultiFrontierArtifactResult =
|
|
249
|
+
| {
|
|
250
|
+
accepted: true;
|
|
251
|
+
deduplicated: boolean;
|
|
252
|
+
artifact: PersistedMultiFrontierArtifact;
|
|
253
|
+
run: MultiFrontierStoredRun;
|
|
254
|
+
}
|
|
255
|
+
| {
|
|
256
|
+
accepted: false;
|
|
257
|
+
reason:
|
|
258
|
+
| "missing-run"
|
|
259
|
+
| "artifact-conflict"
|
|
260
|
+
| "missing-participant"
|
|
261
|
+
| "missing-superseded-artifact"
|
|
262
|
+
| "artifact-limit-reached";
|
|
263
|
+
run: MultiFrontierStoredRun | null;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const TERMINAL_PHASES = new Set<MultiFrontierPhase>([
|
|
267
|
+
"completed",
|
|
268
|
+
"failed",
|
|
269
|
+
"canceled",
|
|
270
|
+
]);
|
|
271
|
+
const SAFE_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,191}$/;
|
|
272
|
+
const SAFE_CONTENT_HASH = /^[a-f0-9]{64}$/;
|
|
273
|
+
const SAFE_FILE_REF = /^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[A-Za-z0-9._/@+-]+$/;
|
|
274
|
+
const MAX_ARTIFACT_TITLE_BYTES = 280;
|
|
275
|
+
const MAX_ARTIFACT_SUMMARY_BYTES = 8 * 1024;
|
|
276
|
+
const MAX_ARTIFACT_FILE_REFS = 40;
|
|
277
|
+
const MAX_ARTIFACT_TEST_SUMMARIES = 40;
|
|
278
|
+
const MAX_ARTIFACT_TEST_NAME_BYTES = 280;
|
|
279
|
+
const MAX_ARTIFACT_TEST_SUMMARY_BYTES = 2 * 1024;
|
|
280
|
+
export const MAX_MULTI_FRONTIER_ARTIFACTS_PER_RUN = 200;
|
|
281
|
+
export const DEFAULT_MULTI_FRONTIER_PARTICIPANT_EVENT_RETENTION: MultiFrontierParticipantEventRetentionLimits =
|
|
282
|
+
{
|
|
283
|
+
maxEventCount: 2_000,
|
|
284
|
+
maxBytes: 1_000_000,
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
/** All multi-frontier state stays alongside the existing local Code store. */
|
|
288
|
+
export function multiFrontierRunsStoreRoot(): string {
|
|
289
|
+
return path.join(codeAgentStoreRoot(), "multi-frontier");
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function multiFrontierRunsDir(): string {
|
|
293
|
+
return path.join(multiFrontierRunsStoreRoot(), "runs");
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function multiFrontierParticipantEventsDir(): string {
|
|
297
|
+
return path.join(multiFrontierRunsStoreRoot(), "events");
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function multiFrontierArtifactsDir(): string {
|
|
301
|
+
return path.join(multiFrontierRunsStoreRoot(), "artifacts");
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export function createMultiFrontierRun(
|
|
305
|
+
input: CreateMultiFrontierRunInput,
|
|
306
|
+
): MultiFrontierStoredRun {
|
|
307
|
+
assertSafeId(input.collaborationId, "collaboration id");
|
|
308
|
+
if (input.workspaceId !== undefined) {
|
|
309
|
+
assertSafeId(input.workspaceId, "workspace id");
|
|
310
|
+
}
|
|
311
|
+
assertParticipants(input.participants);
|
|
312
|
+
if (getMultiFrontierRun(input.collaborationId)) {
|
|
313
|
+
throw new Error(
|
|
314
|
+
`Multi-frontier run already exists: ${input.collaborationId}`,
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
const now = new Date().toISOString();
|
|
318
|
+
const state: MultiFrontierStoredRun = {
|
|
319
|
+
schemaVersion: 1,
|
|
320
|
+
collaborationId: input.collaborationId,
|
|
321
|
+
...(input.workspaceId ? { workspaceId: input.workspaceId } : {}),
|
|
322
|
+
phase: input.phase ?? "proposing",
|
|
323
|
+
participants: input.participants.map((participant) => ({
|
|
324
|
+
...participant,
|
|
325
|
+
capabilities: [...(participant.capabilities ?? [])],
|
|
326
|
+
role: "watchdog",
|
|
327
|
+
permission: "read_only",
|
|
328
|
+
})),
|
|
329
|
+
driver: null,
|
|
330
|
+
approval: { ...(input.approval ?? { state: "not_required" }) },
|
|
331
|
+
checkpointIds: [...(input.checkpointIds ?? [])],
|
|
332
|
+
round: 1,
|
|
333
|
+
proposalIds: [],
|
|
334
|
+
reviewIds: [],
|
|
335
|
+
autoContinueAfterAgreement: input.autoContinueAfterAgreement ?? false,
|
|
336
|
+
createdAt: now,
|
|
337
|
+
updatedAt: now,
|
|
338
|
+
};
|
|
339
|
+
writeNewMultiFrontierRun(state);
|
|
340
|
+
return state;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function getMultiFrontierRun(
|
|
344
|
+
collaborationId: string,
|
|
345
|
+
): MultiFrontierStoredRun | null {
|
|
346
|
+
if (!SAFE_ID.test(collaborationId)) return null;
|
|
347
|
+
return readStoredRun(multiFrontierRunPath(collaborationId));
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export function listMultiFrontierRuns(): MultiFrontierStoredRun[] {
|
|
351
|
+
const directory = multiFrontierRunsDir();
|
|
352
|
+
if (!fs.existsSync(directory)) return [];
|
|
353
|
+
return fs
|
|
354
|
+
.readdirSync(directory)
|
|
355
|
+
.filter((file) => file.endsWith(".json"))
|
|
356
|
+
.map((file) => readStoredRun(path.join(directory, file)))
|
|
357
|
+
.filter((run): run is MultiFrontierStoredRun => run !== null)
|
|
358
|
+
.sort((left, right) => right.updatedAt.localeCompare(left.updatedAt));
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Recovery never resumes a native participant automatically. Any in-flight
|
|
363
|
+
* driver lease is revoked and requires an explicit, newly fenced activation.
|
|
364
|
+
*/
|
|
365
|
+
export function recoverMultiFrontierRun(
|
|
366
|
+
state: MultiFrontierRunState,
|
|
367
|
+
input: RecoverMultiFrontierRunInput,
|
|
368
|
+
): MultiFrontierRunState {
|
|
369
|
+
assertTimestamp(input.now, "recovery time");
|
|
370
|
+
if (TERMINAL_PHASES.has(state.phase) || state.phase === "paused") {
|
|
371
|
+
return state;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const checkpointId = state.checkpointIds.at(-1);
|
|
375
|
+
return {
|
|
376
|
+
...state,
|
|
377
|
+
phase: "paused",
|
|
378
|
+
participants: state.participants.map((participant) => ({
|
|
379
|
+
...participant,
|
|
380
|
+
role: "watchdog",
|
|
381
|
+
permission: "read_only",
|
|
382
|
+
status: participant.status === "running" ? "waiting" : participant.status,
|
|
383
|
+
})),
|
|
384
|
+
driver: state.driver ? { ...state.driver, leaseState: "revoked" } : null,
|
|
385
|
+
recovery: {
|
|
386
|
+
reason: input.reason,
|
|
387
|
+
recoveredAt: input.now,
|
|
388
|
+
resumablePhase: state.phase,
|
|
389
|
+
...(checkpointId ? { checkpointId } : {}),
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** Persist the recovery decision made by the main-process coordinator. */
|
|
395
|
+
export function recoverStoredMultiFrontierRun(
|
|
396
|
+
collaborationId: string,
|
|
397
|
+
input: RecoverMultiFrontierRunInput,
|
|
398
|
+
): MultiFrontierStoredRun | null {
|
|
399
|
+
return mutateStoredMultiFrontierRun(collaborationId, input.now, (current) => {
|
|
400
|
+
const recovered = recoverMultiFrontierRun(current, input);
|
|
401
|
+
return recovered === current ? current : recovered;
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Applies one durable coordinator-owned state transition under the run lock.
|
|
407
|
+
* A state-shaped result retains proposal and review references by default;
|
|
408
|
+
* returning a full stored record is the explicit escape hatch for a
|
|
409
|
+
* coordinator operation that intentionally changes those references.
|
|
410
|
+
*/
|
|
411
|
+
export function transitionStoredMultiFrontierRun(
|
|
412
|
+
collaborationId: string,
|
|
413
|
+
updatedAt: string,
|
|
414
|
+
transition: MultiFrontierCoordinatorTransition,
|
|
415
|
+
): MultiFrontierStoredRun | null {
|
|
416
|
+
assertSafeId(collaborationId, "collaboration id");
|
|
417
|
+
assertTimestamp(updatedAt, "transition time");
|
|
418
|
+
if (typeof transition !== "function") {
|
|
419
|
+
throw new Error("Invalid multi-frontier coordinator transition.");
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return mutateStoredMultiFrontierRun(collaborationId, updatedAt, (current) => {
|
|
423
|
+
const candidate = transition(cloneStoredMultiFrontierRun(current));
|
|
424
|
+
if (candidate === null) return null;
|
|
425
|
+
if (isThenable(candidate)) {
|
|
426
|
+
throw new Error(
|
|
427
|
+
"Multi-frontier coordinator transitions must be synchronous.",
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
if (
|
|
431
|
+
!candidate ||
|
|
432
|
+
typeof candidate !== "object" ||
|
|
433
|
+
Array.isArray(candidate)
|
|
434
|
+
) {
|
|
435
|
+
throw new Error("Invalid multi-frontier coordinator transition state.");
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const isFullStoredRun = hasStoredRunTimestamps(candidate);
|
|
439
|
+
if (
|
|
440
|
+
!isFullStoredRun &&
|
|
441
|
+
(Object.hasOwn(candidate, "createdAt") ||
|
|
442
|
+
Object.hasOwn(candidate, "updatedAt"))
|
|
443
|
+
) {
|
|
444
|
+
throw new Error("Invalid multi-frontier coordinator transition state.");
|
|
445
|
+
}
|
|
446
|
+
if (
|
|
447
|
+
candidate.schemaVersion !== current.schemaVersion ||
|
|
448
|
+
candidate.collaborationId !== current.collaborationId
|
|
449
|
+
) {
|
|
450
|
+
throw new Error(
|
|
451
|
+
"Multi-frontier coordinator transitions cannot change run identity.",
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
if (isFullStoredRun) {
|
|
455
|
+
if (!isCompleteMultiFrontierStoredRun(candidate)) {
|
|
456
|
+
throw new Error("Invalid multi-frontier coordinator transition state.");
|
|
457
|
+
}
|
|
458
|
+
if (candidate.createdAt !== current.createdAt) {
|
|
459
|
+
throw new Error(
|
|
460
|
+
"Multi-frontier coordinator transitions cannot change creation time.",
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const nextState: MultiFrontierRunState = {
|
|
466
|
+
...candidate,
|
|
467
|
+
...(isFullStoredRun
|
|
468
|
+
? {}
|
|
469
|
+
: {
|
|
470
|
+
proposalIds: [...current.proposalIds],
|
|
471
|
+
reviewIds: [...current.reviewIds],
|
|
472
|
+
}),
|
|
473
|
+
};
|
|
474
|
+
if (!isCompleteMultiFrontierRunState(nextState)) {
|
|
475
|
+
throw new Error("Invalid multi-frontier coordinator transition state.");
|
|
476
|
+
}
|
|
477
|
+
return nextState;
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Coordinators must call this before applying a participant event. Write
|
|
483
|
+
* events are accepted only from the active driver generation.
|
|
484
|
+
*/
|
|
485
|
+
export function canApplyMultiFrontierParticipantEvent(
|
|
486
|
+
state: MultiFrontierRunState,
|
|
487
|
+
event: MultiFrontierParticipantEvent,
|
|
488
|
+
): boolean {
|
|
489
|
+
if (TERMINAL_PHASES.has(state.phase) || state.phase === "paused") {
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
if (
|
|
493
|
+
!state.participants.some(
|
|
494
|
+
(candidate) => candidate.participantId === event.participantId,
|
|
495
|
+
)
|
|
496
|
+
) {
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
if (event.permission === "read_only") return true;
|
|
500
|
+
const driver = state.driver;
|
|
501
|
+
return Boolean(
|
|
502
|
+
state.phase === "implementing" &&
|
|
503
|
+
driver?.leaseState === "active" &&
|
|
504
|
+
driver.participantId === event.participantId &&
|
|
505
|
+
driver.generation === event.generation,
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Explicitly restores a write lease after recovery. The generation increments
|
|
511
|
+
* so an event from the interrupted process can never regain write authority.
|
|
512
|
+
*/
|
|
513
|
+
export function reactivateMultiFrontierDriver(
|
|
514
|
+
state: MultiFrontierRunState,
|
|
515
|
+
participantId: string,
|
|
516
|
+
): MultiFrontierRunState | null {
|
|
517
|
+
if (
|
|
518
|
+
state.phase !== "paused" ||
|
|
519
|
+
!state.recovery ||
|
|
520
|
+
state.recovery.resumablePhase !== "implementing" ||
|
|
521
|
+
state.approval.state === "pending"
|
|
522
|
+
) {
|
|
523
|
+
return null;
|
|
524
|
+
}
|
|
525
|
+
const participant = state.participants.find(
|
|
526
|
+
(candidate) => candidate.participantId === participantId,
|
|
527
|
+
);
|
|
528
|
+
if (!participant || participant.status === "failed") return null;
|
|
529
|
+
|
|
530
|
+
const nextGeneration = (state.driver?.generation ?? 0) + 1;
|
|
531
|
+
return {
|
|
532
|
+
...state,
|
|
533
|
+
phase: state.recovery.resumablePhase,
|
|
534
|
+
participants: state.participants.map((candidate) => ({
|
|
535
|
+
...candidate,
|
|
536
|
+
role: candidate.participantId === participantId ? "driver" : "watchdog",
|
|
537
|
+
permission:
|
|
538
|
+
candidate.participantId === participantId
|
|
539
|
+
? "workspace_write"
|
|
540
|
+
: "read_only",
|
|
541
|
+
status:
|
|
542
|
+
candidate.participantId === participantId
|
|
543
|
+
? "waiting"
|
|
544
|
+
: candidate.status,
|
|
545
|
+
})),
|
|
546
|
+
driver: {
|
|
547
|
+
participantId,
|
|
548
|
+
generation: nextGeneration,
|
|
549
|
+
leaseState: "active",
|
|
550
|
+
},
|
|
551
|
+
recovery: undefined,
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/** Assign the first explicit write lease for an implementing run. */
|
|
556
|
+
export function activateMultiFrontierDriver(
|
|
557
|
+
state: MultiFrontierRunState,
|
|
558
|
+
participantId: string,
|
|
559
|
+
): MultiFrontierRunState | null {
|
|
560
|
+
if (
|
|
561
|
+
state.phase !== "implementing" ||
|
|
562
|
+
state.approval.state === "pending" ||
|
|
563
|
+
state.driver?.leaseState === "active"
|
|
564
|
+
) {
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
const participant = state.participants.find(
|
|
568
|
+
(candidate) => candidate.participantId === participantId,
|
|
569
|
+
);
|
|
570
|
+
if (!participant || participant.status === "failed") return null;
|
|
571
|
+
|
|
572
|
+
return {
|
|
573
|
+
...state,
|
|
574
|
+
participants: state.participants.map((candidate) => ({
|
|
575
|
+
...candidate,
|
|
576
|
+
role: candidate.participantId === participantId ? "driver" : "watchdog",
|
|
577
|
+
permission:
|
|
578
|
+
candidate.participantId === participantId
|
|
579
|
+
? "workspace_write"
|
|
580
|
+
: "read_only",
|
|
581
|
+
})),
|
|
582
|
+
driver: {
|
|
583
|
+
participantId,
|
|
584
|
+
generation: (state.driver?.generation ?? 0) + 1,
|
|
585
|
+
leaseState: "active",
|
|
586
|
+
},
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/** Persist the first explicit driver activation from the main-process coordinator. */
|
|
591
|
+
export function activateStoredMultiFrontierDriver(
|
|
592
|
+
collaborationId: string,
|
|
593
|
+
participantId: string,
|
|
594
|
+
now = new Date().toISOString(),
|
|
595
|
+
): MultiFrontierStoredRun | null {
|
|
596
|
+
assertTimestamp(now, "activation time");
|
|
597
|
+
return mutateStoredMultiFrontierRun(collaborationId, now, (current) =>
|
|
598
|
+
activateMultiFrontierDriver(current, participantId),
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/** Persist an explicit driver reactivation after the human-approved resume. */
|
|
603
|
+
export function reactivateStoredMultiFrontierDriver(
|
|
604
|
+
collaborationId: string,
|
|
605
|
+
participantId: string,
|
|
606
|
+
now = new Date().toISOString(),
|
|
607
|
+
): MultiFrontierStoredRun | null {
|
|
608
|
+
assertTimestamp(now, "reactivation time");
|
|
609
|
+
return mutateStoredMultiFrontierRun(collaborationId, now, (current) =>
|
|
610
|
+
reactivateMultiFrontierDriver(current, participantId),
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Appends an idempotent participant event after the coordinator has fenced it.
|
|
616
|
+
* The event journal is diagnostic; state is mutated only through this guarded
|
|
617
|
+
* coordinator entry point.
|
|
618
|
+
*/
|
|
619
|
+
export function appendMultiFrontierParticipantEvent(
|
|
620
|
+
input: AppendMultiFrontierParticipantEventInput,
|
|
621
|
+
): AppendMultiFrontierParticipantEventResult {
|
|
622
|
+
assertSafeId(input.id, "event id");
|
|
623
|
+
assertSafeId(input.collaborationId, "collaboration id");
|
|
624
|
+
assertSafeId(input.participantId, "participant id");
|
|
625
|
+
const createdAt = input.createdAt ?? new Date().toISOString();
|
|
626
|
+
assertTimestamp(createdAt, "event time");
|
|
627
|
+
|
|
628
|
+
const runPath = multiFrontierRunPath(input.collaborationId);
|
|
629
|
+
return withFileLockSync(runPath, () => {
|
|
630
|
+
const current = readStoredRun(runPath);
|
|
631
|
+
if (!current) return { accepted: false, reason: "missing-run", run: null };
|
|
632
|
+
const existing = listMultiFrontierParticipantEvents(
|
|
633
|
+
input.collaborationId,
|
|
634
|
+
).find((event) => event.id === input.id);
|
|
635
|
+
if (existing) {
|
|
636
|
+
if (!isMatchingParticipantEvent(existing, input)) {
|
|
637
|
+
return { accepted: false, reason: "event-conflict", run: current };
|
|
638
|
+
}
|
|
639
|
+
return {
|
|
640
|
+
accepted: true,
|
|
641
|
+
deduplicated: true,
|
|
642
|
+
event: existing,
|
|
643
|
+
run: current,
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
if (
|
|
647
|
+
!current.participants.some(
|
|
648
|
+
(candidate) => candidate.participantId === input.participantId,
|
|
649
|
+
)
|
|
650
|
+
) {
|
|
651
|
+
return { accepted: false, reason: "missing-participant", run: current };
|
|
652
|
+
}
|
|
653
|
+
if (!canApplyMultiFrontierParticipantEvent(current, input)) {
|
|
654
|
+
return { accepted: false, reason: "stale-driver", run: current };
|
|
655
|
+
}
|
|
656
|
+
const participant = current.participants.find(
|
|
657
|
+
(candidate) => candidate.participantId === input.participantId,
|
|
658
|
+
);
|
|
659
|
+
if (
|
|
660
|
+
input.status !== undefined &&
|
|
661
|
+
(participant?.status === "completed" ||
|
|
662
|
+
participant?.status === "failed") &&
|
|
663
|
+
input.status !== participant.status
|
|
664
|
+
) {
|
|
665
|
+
return { accepted: false, reason: "terminal-participant", run: current };
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const event: PersistedMultiFrontierParticipantEvent = {
|
|
669
|
+
schemaVersion: 1,
|
|
670
|
+
id: input.id,
|
|
671
|
+
collaborationId: input.collaborationId,
|
|
672
|
+
participantId: input.participantId,
|
|
673
|
+
permission: input.permission,
|
|
674
|
+
createdAt,
|
|
675
|
+
...(input.generation === undefined
|
|
676
|
+
? {}
|
|
677
|
+
: { generation: input.generation }),
|
|
678
|
+
...(input.status === undefined ? {} : { status: input.status }),
|
|
679
|
+
};
|
|
680
|
+
appendParticipantEvent(event);
|
|
681
|
+
compactParticipantEventJournal(input.collaborationId);
|
|
682
|
+
const status = input.status;
|
|
683
|
+
const participants = status
|
|
684
|
+
? current.participants.map((candidate) =>
|
|
685
|
+
candidate.participantId === input.participantId
|
|
686
|
+
? { ...candidate, status }
|
|
687
|
+
: candidate,
|
|
688
|
+
)
|
|
689
|
+
: current.participants;
|
|
690
|
+
const run = writeNextStoredRun(
|
|
691
|
+
current,
|
|
692
|
+
{ ...current, participants },
|
|
693
|
+
createdAt,
|
|
694
|
+
);
|
|
695
|
+
return { accepted: true, deduplicated: false, event, run };
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Appends a bounded proposal, review, or checkpoint index record. The
|
|
701
|
+
* coordinator owns both the artifact and its run-state reference under one
|
|
702
|
+
* run lock, so a reader never observes a durable reference without its record.
|
|
703
|
+
*/
|
|
704
|
+
export function appendMultiFrontierArtifact(
|
|
705
|
+
input: AppendMultiFrontierArtifactInput,
|
|
706
|
+
): AppendMultiFrontierArtifactResult {
|
|
707
|
+
assertArtifactInput(input);
|
|
708
|
+
const createdAt = input.createdAt ?? new Date().toISOString();
|
|
709
|
+
assertTimestamp(createdAt, "artifact time");
|
|
710
|
+
const artifact = toPersistedArtifact(input, createdAt);
|
|
711
|
+
const runPath = multiFrontierRunPath(input.collaborationId);
|
|
712
|
+
return withFileLockSync(runPath, () => {
|
|
713
|
+
const current = readStoredRun(runPath);
|
|
714
|
+
if (!current) return { accepted: false, reason: "missing-run", run: null };
|
|
715
|
+
if (
|
|
716
|
+
input.participantId !== undefined &&
|
|
717
|
+
!current.participants.some(
|
|
718
|
+
(participant) => participant.participantId === input.participantId,
|
|
719
|
+
)
|
|
720
|
+
) {
|
|
721
|
+
return { accepted: false, reason: "missing-participant", run: current };
|
|
722
|
+
}
|
|
723
|
+
if (
|
|
724
|
+
input.supersedesArtifactId !== undefined &&
|
|
725
|
+
!readStoredArtifact(
|
|
726
|
+
multiFrontierArtifactPath(
|
|
727
|
+
input.collaborationId,
|
|
728
|
+
input.supersedesArtifactId,
|
|
729
|
+
),
|
|
730
|
+
)
|
|
731
|
+
) {
|
|
732
|
+
return {
|
|
733
|
+
accepted: false,
|
|
734
|
+
reason: "missing-superseded-artifact",
|
|
735
|
+
run: current,
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
const artifactPath = multiFrontierArtifactPath(
|
|
740
|
+
input.collaborationId,
|
|
741
|
+
input.id,
|
|
742
|
+
);
|
|
743
|
+
const existing = readStoredArtifact(artifactPath);
|
|
744
|
+
if (existing) {
|
|
745
|
+
if (!isMatchingArtifact(existing, artifact)) {
|
|
746
|
+
return { accepted: false, reason: "artifact-conflict", run: current };
|
|
747
|
+
}
|
|
748
|
+
const ids = artifactIdsForKind(current, existing.kind);
|
|
749
|
+
const run = ids.includes(existing.id)
|
|
750
|
+
? current
|
|
751
|
+
: writeNextStoredRun(
|
|
752
|
+
current,
|
|
753
|
+
withArtifactId(current, existing.kind, existing.id),
|
|
754
|
+
new Date().toISOString(),
|
|
755
|
+
);
|
|
756
|
+
return {
|
|
757
|
+
accepted: true,
|
|
758
|
+
deduplicated: true,
|
|
759
|
+
artifact: existing,
|
|
760
|
+
run,
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
if (fs.existsSync(artifactPath)) {
|
|
764
|
+
return { accepted: false, reason: "artifact-conflict", run: current };
|
|
765
|
+
}
|
|
766
|
+
if (
|
|
767
|
+
listMultiFrontierArtifacts(input.collaborationId).length >=
|
|
768
|
+
MAX_MULTI_FRONTIER_ARTIFACTS_PER_RUN
|
|
769
|
+
) {
|
|
770
|
+
return {
|
|
771
|
+
accepted: false,
|
|
772
|
+
reason: "artifact-limit-reached",
|
|
773
|
+
run: current,
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
writeJsonFileAtomically(artifactPath, artifact, { mode: 0o600 });
|
|
778
|
+
const ids = artifactIdsForKind(current, artifact.kind);
|
|
779
|
+
const next = ids.includes(artifact.id)
|
|
780
|
+
? current
|
|
781
|
+
: withArtifactId(current, artifact.kind, artifact.id);
|
|
782
|
+
const run = writeNextStoredRun(current, next, createdAt);
|
|
783
|
+
return { accepted: true, deduplicated: false, artifact, run };
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
export function getMultiFrontierArtifact(
|
|
788
|
+
collaborationId: string,
|
|
789
|
+
artifactId: string,
|
|
790
|
+
): PersistedMultiFrontierArtifact | null {
|
|
791
|
+
if (!SAFE_ID.test(collaborationId) || !SAFE_ID.test(artifactId)) return null;
|
|
792
|
+
return readStoredArtifact(
|
|
793
|
+
multiFrontierArtifactPath(collaborationId, artifactId),
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
export function listMultiFrontierArtifacts(
|
|
798
|
+
collaborationId: string,
|
|
799
|
+
): PersistedMultiFrontierArtifact[] {
|
|
800
|
+
if (!SAFE_ID.test(collaborationId)) return [];
|
|
801
|
+
const directory = multiFrontierArtifactsRunDir(collaborationId);
|
|
802
|
+
if (!fs.existsSync(directory)) return [];
|
|
803
|
+
return fs
|
|
804
|
+
.readdirSync(directory)
|
|
805
|
+
.filter((file) => file.endsWith(".json"))
|
|
806
|
+
.map((file) => readStoredArtifact(path.join(directory, file)))
|
|
807
|
+
.filter(
|
|
808
|
+
(artifact): artifact is PersistedMultiFrontierArtifact =>
|
|
809
|
+
artifact !== null,
|
|
810
|
+
)
|
|
811
|
+
.sort((left, right) => left.createdAt.localeCompare(right.createdAt));
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
export function listMultiFrontierParticipantEvents(
|
|
815
|
+
collaborationId: string,
|
|
816
|
+
): PersistedMultiFrontierParticipantEvent[] {
|
|
817
|
+
if (!SAFE_ID.test(collaborationId)) return [];
|
|
818
|
+
const eventPath = multiFrontierParticipantEventsPath(collaborationId);
|
|
819
|
+
if (!fs.existsSync(eventPath)) return [];
|
|
820
|
+
return fs
|
|
821
|
+
.readFileSync(eventPath, "utf-8")
|
|
822
|
+
.split(/\r?\n/)
|
|
823
|
+
.filter(Boolean)
|
|
824
|
+
.map(readParticipantEvent)
|
|
825
|
+
.filter(
|
|
826
|
+
(event): event is PersistedMultiFrontierParticipantEvent =>
|
|
827
|
+
event !== null,
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
export function getMultiFrontierParticipantEventRetention(
|
|
832
|
+
collaborationId: string,
|
|
833
|
+
): MultiFrontierParticipantEventRetention | null {
|
|
834
|
+
if (!SAFE_ID.test(collaborationId)) return null;
|
|
835
|
+
return readParticipantEventRetention(
|
|
836
|
+
multiFrontierParticipantEventRetentionPath(collaborationId),
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Coordinator maintenance for a bounded event journal. It deliberately keeps
|
|
842
|
+
* the newest contiguous tail and a replay marker instead of deleting run state.
|
|
843
|
+
*/
|
|
844
|
+
export function compactMultiFrontierParticipantEvents(
|
|
845
|
+
collaborationId: string,
|
|
846
|
+
limits = DEFAULT_MULTI_FRONTIER_PARTICIPANT_EVENT_RETENTION,
|
|
847
|
+
): MultiFrontierParticipantEventRetention | null {
|
|
848
|
+
assertSafeId(collaborationId, "collaboration id");
|
|
849
|
+
assertRetentionLimits(limits);
|
|
850
|
+
const runPath = multiFrontierRunPath(collaborationId);
|
|
851
|
+
return withFileLockSync(runPath, () => {
|
|
852
|
+
if (!readStoredRun(runPath)) return null;
|
|
853
|
+
return compactParticipantEventJournal(collaborationId, limits);
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
function writeMultiFrontierRun(run: MultiFrontierStoredRun): void {
|
|
858
|
+
writeJsonFileAtomically(multiFrontierRunPath(run.collaborationId), run);
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
function writeNewMultiFrontierRun(run: MultiFrontierStoredRun): void {
|
|
862
|
+
const filePath = multiFrontierRunPath(run.collaborationId);
|
|
863
|
+
withFileLockSync(filePath, () => {
|
|
864
|
+
if (fs.existsSync(filePath)) {
|
|
865
|
+
throw new Error(
|
|
866
|
+
`Multi-frontier run already exists: ${run.collaborationId}`,
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
writeJsonFileAtomically(filePath, run);
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
function writeNextStoredRun(
|
|
874
|
+
current: MultiFrontierStoredRun,
|
|
875
|
+
nextState: MultiFrontierRunState,
|
|
876
|
+
updatedAt: string,
|
|
877
|
+
): MultiFrontierStoredRun {
|
|
878
|
+
const next: MultiFrontierStoredRun = {
|
|
879
|
+
...nextState,
|
|
880
|
+
createdAt: current.createdAt,
|
|
881
|
+
updatedAt,
|
|
882
|
+
};
|
|
883
|
+
writeMultiFrontierRun(next);
|
|
884
|
+
return next;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
function appendParticipantEvent(
|
|
888
|
+
event: PersistedMultiFrontierParticipantEvent,
|
|
889
|
+
): void {
|
|
890
|
+
appendUniqueJsonLineAtomically(
|
|
891
|
+
multiFrontierParticipantEventsPath(event.collaborationId),
|
|
892
|
+
event,
|
|
893
|
+
readParticipantEventValue,
|
|
894
|
+
{ mode: 0o600 },
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
function compactParticipantEventJournal(
|
|
899
|
+
collaborationId: string,
|
|
900
|
+
limits = DEFAULT_MULTI_FRONTIER_PARTICIPANT_EVENT_RETENTION,
|
|
901
|
+
): MultiFrontierParticipantEventRetention {
|
|
902
|
+
const eventPath = multiFrontierParticipantEventsPath(collaborationId);
|
|
903
|
+
return withFileLockSync(eventPath, () => {
|
|
904
|
+
const previous = readParticipantEventRetention(
|
|
905
|
+
multiFrontierParticipantEventRetentionPath(collaborationId),
|
|
906
|
+
);
|
|
907
|
+
const events = listMultiFrontierParticipantEvents(collaborationId);
|
|
908
|
+
const retained: PersistedMultiFrontierParticipantEvent[] = [];
|
|
909
|
+
let retainedByteCount = 0;
|
|
910
|
+
for (const event of [...events].reverse()) {
|
|
911
|
+
const bytes = eventLineByteLength(event);
|
|
912
|
+
if (
|
|
913
|
+
retained.length >= limits.maxEventCount ||
|
|
914
|
+
retainedByteCount + bytes > limits.maxBytes
|
|
915
|
+
) {
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
retained.push(event);
|
|
919
|
+
retainedByteCount += bytes;
|
|
920
|
+
}
|
|
921
|
+
retained.reverse();
|
|
922
|
+
const retainedIds = new Set(retained.map((event) => event.id));
|
|
923
|
+
const dropped = events.filter((event) => !retainedIds.has(event.id));
|
|
924
|
+
if (dropped.length > 0) {
|
|
925
|
+
writeTextFileAtomically(
|
|
926
|
+
eventPath,
|
|
927
|
+
retained.map((event) => `${JSON.stringify(event)}\n`).join(""),
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
const retention: MultiFrontierParticipantEventRetention = {
|
|
931
|
+
schemaVersion: 1,
|
|
932
|
+
retainedEventCount: retained.length,
|
|
933
|
+
retainedByteCount,
|
|
934
|
+
droppedEventCount: (previous?.droppedEventCount ?? 0) + dropped.length,
|
|
935
|
+
droppedByteCount:
|
|
936
|
+
(previous?.droppedByteCount ?? 0) +
|
|
937
|
+
dropped.reduce((total, event) => total + eventLineByteLength(event), 0),
|
|
938
|
+
truncated: (previous?.truncated ?? false) || dropped.length > 0,
|
|
939
|
+
replay: {
|
|
940
|
+
requiresSnapshot: (previous?.truncated ?? false) || dropped.length > 0,
|
|
941
|
+
...(retained[0] ? { firstRetainedEventId: retained[0].id } : {}),
|
|
942
|
+
},
|
|
943
|
+
};
|
|
944
|
+
writeJsonFileAtomically(
|
|
945
|
+
multiFrontierParticipantEventRetentionPath(collaborationId),
|
|
946
|
+
retention,
|
|
947
|
+
{ mode: 0o600 },
|
|
948
|
+
);
|
|
949
|
+
return retention;
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
function mutateStoredMultiFrontierRun(
|
|
954
|
+
collaborationId: string,
|
|
955
|
+
updatedAt: string,
|
|
956
|
+
mutate: (current: MultiFrontierStoredRun) => MultiFrontierRunState | null,
|
|
957
|
+
): MultiFrontierStoredRun | null {
|
|
958
|
+
const filePath = multiFrontierRunPath(collaborationId);
|
|
959
|
+
return withFileLockSync(filePath, () => {
|
|
960
|
+
const current = readStoredRun(filePath);
|
|
961
|
+
if (!current) return null;
|
|
962
|
+
const nextState = mutate(current);
|
|
963
|
+
if (!nextState) return null;
|
|
964
|
+
const next: MultiFrontierStoredRun = {
|
|
965
|
+
...nextState,
|
|
966
|
+
createdAt: current.createdAt,
|
|
967
|
+
updatedAt,
|
|
968
|
+
};
|
|
969
|
+
writeMultiFrontierRun(next);
|
|
970
|
+
return next;
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
function multiFrontierRunPath(collaborationId: string): string {
|
|
975
|
+
return path.join(multiFrontierRunsDir(), `${collaborationId}.json`);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
function multiFrontierParticipantEventsPath(collaborationId: string): string {
|
|
979
|
+
return path.join(
|
|
980
|
+
multiFrontierParticipantEventsDir(),
|
|
981
|
+
`${collaborationId}.jsonl`,
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
function multiFrontierParticipantEventRetentionPath(
|
|
986
|
+
collaborationId: string,
|
|
987
|
+
): string {
|
|
988
|
+
return path.join(
|
|
989
|
+
multiFrontierParticipantEventsDir(),
|
|
990
|
+
`${collaborationId}.retention.json`,
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
function multiFrontierArtifactsRunDir(collaborationId: string): string {
|
|
995
|
+
return path.join(multiFrontierArtifactsDir(), collaborationId);
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
function multiFrontierArtifactPath(
|
|
999
|
+
collaborationId: string,
|
|
1000
|
+
artifactId: string,
|
|
1001
|
+
): string {
|
|
1002
|
+
return path.join(
|
|
1003
|
+
multiFrontierArtifactsRunDir(collaborationId),
|
|
1004
|
+
`${artifactId}.json`,
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
function readStoredRun(filePath: string): MultiFrontierStoredRun | null {
|
|
1009
|
+
try {
|
|
1010
|
+
const raw = JSON.parse(fs.readFileSync(filePath, "utf-8")) as unknown;
|
|
1011
|
+
const normalized = normalizeStoredRunDefaults(raw);
|
|
1012
|
+
return isCompleteMultiFrontierStoredRun(normalized) ? normalized : null;
|
|
1013
|
+
} catch {
|
|
1014
|
+
return null;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
function isCompleteMultiFrontierStoredRun(
|
|
1019
|
+
value: unknown,
|
|
1020
|
+
): value is MultiFrontierStoredRun {
|
|
1021
|
+
if (!hasStoredRunTimestamps(value)) return false;
|
|
1022
|
+
return (
|
|
1023
|
+
isCompleteMultiFrontierRunState(value) &&
|
|
1024
|
+
!Number.isNaN(Date.parse(value.createdAt)) &&
|
|
1025
|
+
!Number.isNaN(Date.parse(value.updatedAt))
|
|
1026
|
+
);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
function isCompleteMultiFrontierRunState(
|
|
1030
|
+
value: unknown,
|
|
1031
|
+
): value is MultiFrontierRunState {
|
|
1032
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1033
|
+
const run = value as Partial<MultiFrontierRunState>;
|
|
1034
|
+
return (
|
|
1035
|
+
run.schemaVersion === 1 &&
|
|
1036
|
+
typeof run.collaborationId === "string" &&
|
|
1037
|
+
SAFE_ID.test(run.collaborationId) &&
|
|
1038
|
+
(run.workspaceId === undefined ||
|
|
1039
|
+
(typeof run.workspaceId === "string" && SAFE_ID.test(run.workspaceId))) &&
|
|
1040
|
+
isPhase(run.phase) &&
|
|
1041
|
+
isStoredRunParticipantsAndDriverValid(run.participants, run.driver) &&
|
|
1042
|
+
isApproval(run.approval) &&
|
|
1043
|
+
Array.isArray(run.checkpointIds) &&
|
|
1044
|
+
run.checkpointIds.every(
|
|
1045
|
+
(checkpointId) => typeof checkpointId === "string",
|
|
1046
|
+
) &&
|
|
1047
|
+
typeof run.round === "number" &&
|
|
1048
|
+
Number.isInteger(run.round) &&
|
|
1049
|
+
run.round >= 1 &&
|
|
1050
|
+
isStringArray(run.proposalIds) &&
|
|
1051
|
+
isStringArray(run.reviewIds) &&
|
|
1052
|
+
typeof run.autoContinueAfterAgreement === "boolean" &&
|
|
1053
|
+
(run.recovery === undefined || isRecovery(run.recovery))
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
function normalizeStoredRunDefaults(value: unknown): unknown {
|
|
1058
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return value;
|
|
1059
|
+
if (!Object.hasOwn(value, "autoContinueAfterAgreement")) {
|
|
1060
|
+
return { ...value, autoContinueAfterAgreement: false };
|
|
1061
|
+
}
|
|
1062
|
+
return value;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
function hasStoredRunTimestamps(
|
|
1066
|
+
value: unknown,
|
|
1067
|
+
): value is MultiFrontierStoredRun {
|
|
1068
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1069
|
+
const run = value as Partial<MultiFrontierStoredRun>;
|
|
1070
|
+
return typeof run.createdAt === "string" && typeof run.updatedAt === "string";
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
function cloneStoredMultiFrontierRun(
|
|
1074
|
+
run: MultiFrontierStoredRun,
|
|
1075
|
+
): MultiFrontierStoredRun {
|
|
1076
|
+
return JSON.parse(JSON.stringify(run)) as MultiFrontierStoredRun;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
function isThenable(value: unknown): value is PromiseLike<unknown> {
|
|
1080
|
+
return (
|
|
1081
|
+
Boolean(value) &&
|
|
1082
|
+
(typeof value === "object" || typeof value === "function") &&
|
|
1083
|
+
typeof (value as { then?: unknown }).then === "function"
|
|
1084
|
+
);
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
function readParticipantEvent(
|
|
1088
|
+
line: string,
|
|
1089
|
+
): PersistedMultiFrontierParticipantEvent | null {
|
|
1090
|
+
try {
|
|
1091
|
+
return readParticipantEventValue(JSON.parse(line) as unknown);
|
|
1092
|
+
} catch {
|
|
1093
|
+
return null;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
function readParticipantEventValue(
|
|
1098
|
+
raw: unknown,
|
|
1099
|
+
): PersistedMultiFrontierParticipantEvent | null {
|
|
1100
|
+
try {
|
|
1101
|
+
if (!raw || typeof raw !== "object") return null;
|
|
1102
|
+
const event = raw as Partial<PersistedMultiFrontierParticipantEvent>;
|
|
1103
|
+
if (
|
|
1104
|
+
event.schemaVersion !== 1 ||
|
|
1105
|
+
typeof event.id !== "string" ||
|
|
1106
|
+
typeof event.collaborationId !== "string" ||
|
|
1107
|
+
typeof event.participantId !== "string" ||
|
|
1108
|
+
!isPermission(event.permission) ||
|
|
1109
|
+
(event.generation !== undefined &&
|
|
1110
|
+
typeof event.generation !== "number") ||
|
|
1111
|
+
(event.status !== undefined && !isParticipantStatus(event.status)) ||
|
|
1112
|
+
typeof event.createdAt !== "string" ||
|
|
1113
|
+
Number.isNaN(Date.parse(event.createdAt))
|
|
1114
|
+
) {
|
|
1115
|
+
return null;
|
|
1116
|
+
}
|
|
1117
|
+
return event as PersistedMultiFrontierParticipantEvent;
|
|
1118
|
+
} catch {
|
|
1119
|
+
return null;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
function readStoredArtifact(
|
|
1124
|
+
filePath: string,
|
|
1125
|
+
): PersistedMultiFrontierArtifact | null {
|
|
1126
|
+
try {
|
|
1127
|
+
return readArtifactValue(
|
|
1128
|
+
JSON.parse(fs.readFileSync(filePath, "utf-8")) as unknown,
|
|
1129
|
+
);
|
|
1130
|
+
} catch {
|
|
1131
|
+
return null;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
function readArtifactValue(
|
|
1136
|
+
raw: unknown,
|
|
1137
|
+
): PersistedMultiFrontierArtifact | null {
|
|
1138
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
1139
|
+
const artifact = raw as Partial<PersistedMultiFrontierArtifact>;
|
|
1140
|
+
if (
|
|
1141
|
+
artifact.schemaVersion !== 1 ||
|
|
1142
|
+
!isSafeId(artifact.id) ||
|
|
1143
|
+
!isSafeId(artifact.collaborationId) ||
|
|
1144
|
+
!isArtifactKind(artifact.kind) ||
|
|
1145
|
+
typeof artifact.createdAt !== "string" ||
|
|
1146
|
+
Number.isNaN(Date.parse(artifact.createdAt)) ||
|
|
1147
|
+
(artifact.participantId !== undefined &&
|
|
1148
|
+
!isSafeId(artifact.participantId)) ||
|
|
1149
|
+
!isBoundedText(artifact.title, MAX_ARTIFACT_TITLE_BYTES) ||
|
|
1150
|
+
!isArtifactSummary(artifact.summary) ||
|
|
1151
|
+
(artifact.supersedesArtifactId !== undefined &&
|
|
1152
|
+
!isSafeId(artifact.supersedesArtifactId)) ||
|
|
1153
|
+
(artifact.contentHash !== undefined &&
|
|
1154
|
+
!SAFE_CONTENT_HASH.test(artifact.contentHash)) ||
|
|
1155
|
+
!isArtifactFileRefs(artifact.fileRefs) ||
|
|
1156
|
+
!isArtifactTestSummaries(artifact.testSummary) ||
|
|
1157
|
+
!isOrchestrationArtifact(artifact.orchestration)
|
|
1158
|
+
) {
|
|
1159
|
+
return null;
|
|
1160
|
+
}
|
|
1161
|
+
return artifact as PersistedMultiFrontierArtifact;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
function readParticipantEventRetention(
|
|
1165
|
+
filePath: string,
|
|
1166
|
+
): MultiFrontierParticipantEventRetention | null {
|
|
1167
|
+
try {
|
|
1168
|
+
const raw = JSON.parse(fs.readFileSync(filePath, "utf-8")) as unknown;
|
|
1169
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
1170
|
+
const retention = raw as Partial<MultiFrontierParticipantEventRetention>;
|
|
1171
|
+
if (
|
|
1172
|
+
retention.schemaVersion !== 1 ||
|
|
1173
|
+
!isNonNegativeInteger(retention.retainedEventCount) ||
|
|
1174
|
+
!isNonNegativeInteger(retention.retainedByteCount) ||
|
|
1175
|
+
!isNonNegativeInteger(retention.droppedEventCount) ||
|
|
1176
|
+
!isNonNegativeInteger(retention.droppedByteCount) ||
|
|
1177
|
+
typeof retention.truncated !== "boolean" ||
|
|
1178
|
+
!retention.replay ||
|
|
1179
|
+
typeof retention.replay !== "object" ||
|
|
1180
|
+
typeof retention.replay.requiresSnapshot !== "boolean" ||
|
|
1181
|
+
(retention.replay.firstRetainedEventId !== undefined &&
|
|
1182
|
+
!isSafeId(retention.replay.firstRetainedEventId))
|
|
1183
|
+
) {
|
|
1184
|
+
return null;
|
|
1185
|
+
}
|
|
1186
|
+
return retention as MultiFrontierParticipantEventRetention;
|
|
1187
|
+
} catch {
|
|
1188
|
+
return null;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
function assertArtifactInput(input: AppendMultiFrontierArtifactInput): void {
|
|
1193
|
+
assertAllowlistedArtifactInput(input);
|
|
1194
|
+
assertSafeId(input.id, "artifact id");
|
|
1195
|
+
assertSafeId(input.collaborationId, "collaboration id");
|
|
1196
|
+
if (!isArtifactKind(input.kind))
|
|
1197
|
+
throw new Error("Invalid multi-frontier artifact kind.");
|
|
1198
|
+
if (input.participantId !== undefined) {
|
|
1199
|
+
assertSafeId(input.participantId, "participant id");
|
|
1200
|
+
}
|
|
1201
|
+
assertBoundedText(input.title, MAX_ARTIFACT_TITLE_BYTES, "artifact title");
|
|
1202
|
+
if (!isArtifactSummary(input.summary)) {
|
|
1203
|
+
throw new Error("Invalid multi-frontier artifact summary.");
|
|
1204
|
+
}
|
|
1205
|
+
if (input.supersedesArtifactId !== undefined) {
|
|
1206
|
+
assertSafeId(input.supersedesArtifactId, "superseded artifact id");
|
|
1207
|
+
}
|
|
1208
|
+
if (
|
|
1209
|
+
input.contentHash !== undefined &&
|
|
1210
|
+
!SAFE_CONTENT_HASH.test(input.contentHash)
|
|
1211
|
+
) {
|
|
1212
|
+
throw new Error("Invalid multi-frontier artifact content hash.");
|
|
1213
|
+
}
|
|
1214
|
+
if (!isArtifactFileRefs(input.fileRefs)) {
|
|
1215
|
+
throw new Error("Invalid multi-frontier artifact file references.");
|
|
1216
|
+
}
|
|
1217
|
+
if (!isArtifactTestSummaries(input.testSummary)) {
|
|
1218
|
+
throw new Error("Invalid multi-frontier artifact test summary.");
|
|
1219
|
+
}
|
|
1220
|
+
if (!isOrchestrationArtifact(input.orchestration)) {
|
|
1221
|
+
throw new Error("Invalid multi-frontier orchestration artifact.");
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
function assertAllowlistedArtifactInput(
|
|
1226
|
+
input: AppendMultiFrontierArtifactInput,
|
|
1227
|
+
): void {
|
|
1228
|
+
const allowed = new Set([
|
|
1229
|
+
"id",
|
|
1230
|
+
"collaborationId",
|
|
1231
|
+
"kind",
|
|
1232
|
+
"createdAt",
|
|
1233
|
+
"participantId",
|
|
1234
|
+
"title",
|
|
1235
|
+
"summary",
|
|
1236
|
+
"supersedesArtifactId",
|
|
1237
|
+
"contentHash",
|
|
1238
|
+
"fileRefs",
|
|
1239
|
+
"testSummary",
|
|
1240
|
+
"orchestration",
|
|
1241
|
+
]);
|
|
1242
|
+
if (
|
|
1243
|
+
!input ||
|
|
1244
|
+
typeof input !== "object" ||
|
|
1245
|
+
Array.isArray(input) ||
|
|
1246
|
+
Object.keys(input).some((key) => !allowed.has(key))
|
|
1247
|
+
) {
|
|
1248
|
+
throw new Error(
|
|
1249
|
+
"Multi-frontier artifacts only accept allowlisted summary fields.",
|
|
1250
|
+
);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
function toPersistedArtifact(
|
|
1255
|
+
input: AppendMultiFrontierArtifactInput,
|
|
1256
|
+
createdAt: string,
|
|
1257
|
+
): PersistedMultiFrontierArtifact {
|
|
1258
|
+
return {
|
|
1259
|
+
schemaVersion: 1,
|
|
1260
|
+
id: input.id,
|
|
1261
|
+
collaborationId: input.collaborationId,
|
|
1262
|
+
kind: input.kind,
|
|
1263
|
+
createdAt,
|
|
1264
|
+
title: input.title,
|
|
1265
|
+
summary: input.summary,
|
|
1266
|
+
...(input.participantId === undefined
|
|
1267
|
+
? {}
|
|
1268
|
+
: { participantId: input.participantId }),
|
|
1269
|
+
...(input.supersedesArtifactId === undefined
|
|
1270
|
+
? {}
|
|
1271
|
+
: { supersedesArtifactId: input.supersedesArtifactId }),
|
|
1272
|
+
...(input.contentHash === undefined
|
|
1273
|
+
? {}
|
|
1274
|
+
: { contentHash: input.contentHash }),
|
|
1275
|
+
...(input.fileRefs === undefined ? {} : { fileRefs: [...input.fileRefs] }),
|
|
1276
|
+
...(input.testSummary === undefined
|
|
1277
|
+
? {}
|
|
1278
|
+
: {
|
|
1279
|
+
testSummary: input.testSummary.map((summary) => ({ ...summary })),
|
|
1280
|
+
}),
|
|
1281
|
+
...(input.orchestration === undefined
|
|
1282
|
+
? {}
|
|
1283
|
+
: { orchestration: cloneOrchestrationArtifact(input.orchestration) }),
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
function artifactIdsForKind(
|
|
1288
|
+
run: MultiFrontierStoredRun,
|
|
1289
|
+
kind: MultiFrontierArtifactKind,
|
|
1290
|
+
): string[] {
|
|
1291
|
+
if (kind === "proposal") return run.proposalIds;
|
|
1292
|
+
if (kind === "review") return run.reviewIds;
|
|
1293
|
+
return run.checkpointIds;
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
function withArtifactId(
|
|
1297
|
+
run: MultiFrontierStoredRun,
|
|
1298
|
+
kind: MultiFrontierArtifactKind,
|
|
1299
|
+
artifactId: string,
|
|
1300
|
+
): MultiFrontierStoredRun {
|
|
1301
|
+
if (kind === "proposal") {
|
|
1302
|
+
return { ...run, proposalIds: [...run.proposalIds, artifactId] };
|
|
1303
|
+
}
|
|
1304
|
+
if (kind === "review") {
|
|
1305
|
+
return { ...run, reviewIds: [...run.reviewIds, artifactId] };
|
|
1306
|
+
}
|
|
1307
|
+
return { ...run, checkpointIds: [...run.checkpointIds, artifactId] };
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
function isMatchingArtifact(
|
|
1311
|
+
existing: PersistedMultiFrontierArtifact,
|
|
1312
|
+
candidate: PersistedMultiFrontierArtifact,
|
|
1313
|
+
): boolean {
|
|
1314
|
+
return JSON.stringify(existing) === JSON.stringify(candidate);
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
function isArtifactKind(value: unknown): value is MultiFrontierArtifactKind {
|
|
1318
|
+
return value === "proposal" || value === "review" || value === "checkpoint";
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
function isArtifactSummary(value: unknown): value is string {
|
|
1322
|
+
return (
|
|
1323
|
+
isBoundedText(value, MAX_ARTIFACT_SUMMARY_BYTES) &&
|
|
1324
|
+
!/(?:^|\n)diff --git\s|(?:^|\n)@@\s+-\d+/m.test(value)
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
function isArtifactFileRefs(value: unknown): value is string[] | undefined {
|
|
1329
|
+
return (
|
|
1330
|
+
value === undefined ||
|
|
1331
|
+
(Array.isArray(value) &&
|
|
1332
|
+
value.length <= MAX_ARTIFACT_FILE_REFS &&
|
|
1333
|
+
value.every(
|
|
1334
|
+
(fileRef) =>
|
|
1335
|
+
typeof fileRef === "string" &&
|
|
1336
|
+
Buffer.byteLength(fileRef, "utf-8") <= 512 &&
|
|
1337
|
+
SAFE_FILE_REF.test(fileRef),
|
|
1338
|
+
))
|
|
1339
|
+
);
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
function isArtifactTestSummaries(
|
|
1343
|
+
value: unknown,
|
|
1344
|
+
): value is MultiFrontierArtifactTestSummary[] | undefined {
|
|
1345
|
+
return (
|
|
1346
|
+
value === undefined ||
|
|
1347
|
+
(Array.isArray(value) &&
|
|
1348
|
+
value.length <= MAX_ARTIFACT_TEST_SUMMARIES &&
|
|
1349
|
+
value.every(
|
|
1350
|
+
(summary) =>
|
|
1351
|
+
Boolean(summary) &&
|
|
1352
|
+
typeof summary === "object" &&
|
|
1353
|
+
isBoundedText(
|
|
1354
|
+
(summary as MultiFrontierArtifactTestSummary).name,
|
|
1355
|
+
MAX_ARTIFACT_TEST_NAME_BYTES,
|
|
1356
|
+
) &&
|
|
1357
|
+
["passed", "failed", "skipped"].includes(
|
|
1358
|
+
(summary as MultiFrontierArtifactTestSummary).status,
|
|
1359
|
+
) &&
|
|
1360
|
+
((summary as MultiFrontierArtifactTestSummary).summary ===
|
|
1361
|
+
undefined ||
|
|
1362
|
+
isBoundedText(
|
|
1363
|
+
(summary as MultiFrontierArtifactTestSummary).summary,
|
|
1364
|
+
MAX_ARTIFACT_TEST_SUMMARY_BYTES,
|
|
1365
|
+
)),
|
|
1366
|
+
))
|
|
1367
|
+
);
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
function isOrchestrationArtifact(
|
|
1371
|
+
value: unknown,
|
|
1372
|
+
): value is MultiFrontierOrchestrationArtifact | undefined {
|
|
1373
|
+
if (value === undefined) return true;
|
|
1374
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1375
|
+
const artifact = value as Partial<MultiFrontierOrchestrationArtifact>;
|
|
1376
|
+
return (
|
|
1377
|
+
hasExactKeys(artifact, [
|
|
1378
|
+
"id",
|
|
1379
|
+
"kind",
|
|
1380
|
+
"round",
|
|
1381
|
+
"participantId",
|
|
1382
|
+
"text",
|
|
1383
|
+
"attribution",
|
|
1384
|
+
"supersedesArtifactId",
|
|
1385
|
+
"metadata",
|
|
1386
|
+
]) &&
|
|
1387
|
+
isSafeId(artifact.id) &&
|
|
1388
|
+
[
|
|
1389
|
+
"proposal",
|
|
1390
|
+
"cross_review",
|
|
1391
|
+
"revision",
|
|
1392
|
+
"synthesis",
|
|
1393
|
+
"checkpoint",
|
|
1394
|
+
"watchdog_review",
|
|
1395
|
+
"finding_disposition",
|
|
1396
|
+
"completion",
|
|
1397
|
+
].includes(artifact.kind ?? "") &&
|
|
1398
|
+
Number.isSafeInteger(artifact.round) &&
|
|
1399
|
+
artifact.round! >= 1 &&
|
|
1400
|
+
artifact.round! <= 3 &&
|
|
1401
|
+
(artifact.participantId === undefined ||
|
|
1402
|
+
isSafeId(artifact.participantId)) &&
|
|
1403
|
+
isSafeOrchestrationText(artifact.text) &&
|
|
1404
|
+
isOrchestrationAttribution(artifact.attribution) &&
|
|
1405
|
+
(artifact.supersedesArtifactId === undefined ||
|
|
1406
|
+
isSafeId(artifact.supersedesArtifactId)) &&
|
|
1407
|
+
isSafeOrchestrationMetadata(artifact.kind!, artifact.metadata)
|
|
1408
|
+
);
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
function hasExactKeys(value: object, allowed: readonly string[]): boolean {
|
|
1412
|
+
return Object.keys(value).every((key) => allowed.includes(key));
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
function isOrchestrationAttribution(
|
|
1416
|
+
value: unknown,
|
|
1417
|
+
): value is MultiFrontierOrchestrationArtifact["attribution"] {
|
|
1418
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1419
|
+
const attribution = value as Partial<
|
|
1420
|
+
MultiFrontierOrchestrationArtifact["attribution"]
|
|
1421
|
+
>;
|
|
1422
|
+
return (
|
|
1423
|
+
hasExactKeys(attribution as Record<string, unknown>, [
|
|
1424
|
+
"participantIds",
|
|
1425
|
+
"sourceArtifactIds",
|
|
1426
|
+
]) &&
|
|
1427
|
+
isSafeIdArray(attribution.participantIds, 2) &&
|
|
1428
|
+
isSafeIdArray(
|
|
1429
|
+
attribution.sourceArtifactIds,
|
|
1430
|
+
MAX_MULTI_FRONTIER_ARTIFACTS_PER_RUN,
|
|
1431
|
+
)
|
|
1432
|
+
);
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
function isSafeIdArray(value: unknown, max: number): value is string[] {
|
|
1436
|
+
return (
|
|
1437
|
+
Array.isArray(value) &&
|
|
1438
|
+
value.length <= max &&
|
|
1439
|
+
value.every((item) => isSafeId(item))
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
function isSafeOrchestrationText(value: unknown): value is string {
|
|
1444
|
+
return (
|
|
1445
|
+
isArtifactSummary(value) &&
|
|
1446
|
+
!/(?:bearer\s+|api[_-]?key\s*[:=]|authorization\s*[:=]|(?:sk|rk|pk)[_-][A-Za-z0-9_-]{12,}|(?:access|refresh)[_-]?token\s*[:=])/i.test(
|
|
1447
|
+
value,
|
|
1448
|
+
)
|
|
1449
|
+
);
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
function isSafeOrchestrationMetadata(
|
|
1453
|
+
kind: NonNullable<MultiFrontierOrchestrationArtifact["kind"]>,
|
|
1454
|
+
value: unknown,
|
|
1455
|
+
): value is Record<string, unknown> | undefined {
|
|
1456
|
+
const allowedKeys = metadataKeysForOrchestrationKind(kind);
|
|
1457
|
+
if (allowedKeys.length === 0) return value === undefined;
|
|
1458
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1459
|
+
const entries = Object.entries(value);
|
|
1460
|
+
if (
|
|
1461
|
+
entries.length === 0 ||
|
|
1462
|
+
entries.some(([key]) => !allowedKeys.includes(key)) ||
|
|
1463
|
+
entries.some(([key]) =>
|
|
1464
|
+
/(token|secret|authorization|credential|password|email|organization|account)/i.test(
|
|
1465
|
+
key,
|
|
1466
|
+
),
|
|
1467
|
+
)
|
|
1468
|
+
) {
|
|
1469
|
+
return false;
|
|
1470
|
+
}
|
|
1471
|
+
try {
|
|
1472
|
+
return (
|
|
1473
|
+
isArtifactSummary(JSON.stringify(value)) &&
|
|
1474
|
+
isValidOrchestrationMetadata(kind, value as Record<string, unknown>)
|
|
1475
|
+
);
|
|
1476
|
+
} catch {
|
|
1477
|
+
return false;
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
function isValidOrchestrationMetadata(
|
|
1482
|
+
kind: NonNullable<MultiFrontierOrchestrationArtifact["kind"]>,
|
|
1483
|
+
metadata: Record<string, unknown>,
|
|
1484
|
+
): boolean {
|
|
1485
|
+
if (kind === "synthesis") {
|
|
1486
|
+
return (
|
|
1487
|
+
typeof metadata.agreed === "boolean" &&
|
|
1488
|
+
typeof metadata.deterministicallyResolved === "boolean" &&
|
|
1489
|
+
(metadata.reversibleResolution === undefined ||
|
|
1490
|
+
isReversibleResolution(metadata.reversibleResolution))
|
|
1491
|
+
);
|
|
1492
|
+
}
|
|
1493
|
+
if (kind === "checkpoint") return isCheckpointBundle(metadata.bundle);
|
|
1494
|
+
if (kind === "cross_review" || kind === "watchdog_review") {
|
|
1495
|
+
return isFindingList(metadata.findings);
|
|
1496
|
+
}
|
|
1497
|
+
if (kind === "finding_disposition") {
|
|
1498
|
+
return isFindingDispositionList(metadata.dispositions);
|
|
1499
|
+
}
|
|
1500
|
+
if (kind === "completion") {
|
|
1501
|
+
return (
|
|
1502
|
+
isCompletionTests(metadata.tests) &&
|
|
1503
|
+
isSafeTextList(metadata.proofRefs, 40) &&
|
|
1504
|
+
isSafeTextList(metadata.remainingRisks, 40)
|
|
1505
|
+
);
|
|
1506
|
+
}
|
|
1507
|
+
return false;
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
function isFindingList(value: unknown): boolean {
|
|
1511
|
+
return (
|
|
1512
|
+
Array.isArray(value) &&
|
|
1513
|
+
value.length <= 40 &&
|
|
1514
|
+
value.every((finding) => {
|
|
1515
|
+
if (!finding || typeof finding !== "object" || Array.isArray(finding))
|
|
1516
|
+
return false;
|
|
1517
|
+
const item = finding as Record<string, unknown>;
|
|
1518
|
+
return (
|
|
1519
|
+
hasExactKeys(item, [
|
|
1520
|
+
"id",
|
|
1521
|
+
"category",
|
|
1522
|
+
"summary",
|
|
1523
|
+
"rawFindingId",
|
|
1524
|
+
"reviewerParticipantId",
|
|
1525
|
+
]) &&
|
|
1526
|
+
isSafeId(item.id) &&
|
|
1527
|
+
isSafeOrchestrationText(item.summary) &&
|
|
1528
|
+
isSafeId(item.rawFindingId) &&
|
|
1529
|
+
isSafeId(item.reviewerParticipantId) &&
|
|
1530
|
+
[
|
|
1531
|
+
"reversible_technical",
|
|
1532
|
+
"intent_or_scope",
|
|
1533
|
+
"destructive_action",
|
|
1534
|
+
"security_or_privacy",
|
|
1535
|
+
"outward_effect",
|
|
1536
|
+
"meaningful_cost_expansion",
|
|
1537
|
+
"irreversible_architecture",
|
|
1538
|
+
].includes(item.category as string)
|
|
1539
|
+
);
|
|
1540
|
+
})
|
|
1541
|
+
);
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
function isFindingDispositionList(value: unknown): boolean {
|
|
1545
|
+
return (
|
|
1546
|
+
Array.isArray(value) &&
|
|
1547
|
+
value.length <= 40 &&
|
|
1548
|
+
value.every((disposition) => {
|
|
1549
|
+
if (
|
|
1550
|
+
!disposition ||
|
|
1551
|
+
typeof disposition !== "object" ||
|
|
1552
|
+
Array.isArray(disposition)
|
|
1553
|
+
)
|
|
1554
|
+
return false;
|
|
1555
|
+
const item = disposition as Record<string, unknown>;
|
|
1556
|
+
return (
|
|
1557
|
+
hasExactKeys(item, ["findingId", "disposition", "reason"]) &&
|
|
1558
|
+
isSafeId(item.findingId) &&
|
|
1559
|
+
["addressed", "rejected", "deferred"].includes(
|
|
1560
|
+
item.disposition as string,
|
|
1561
|
+
) &&
|
|
1562
|
+
isSafeOrchestrationText(item.reason)
|
|
1563
|
+
);
|
|
1564
|
+
})
|
|
1565
|
+
);
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
function isReversibleResolution(value: unknown): boolean {
|
|
1569
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1570
|
+
const item = value as Record<string, unknown>;
|
|
1571
|
+
return (
|
|
1572
|
+
hasExactKeys(item, [
|
|
1573
|
+
"alternatives",
|
|
1574
|
+
"comparator",
|
|
1575
|
+
"selected",
|
|
1576
|
+
"reversibility",
|
|
1577
|
+
]) &&
|
|
1578
|
+
isSafeTextList(item.alternatives, 8) &&
|
|
1579
|
+
isSafeOrchestrationText(item.comparator) &&
|
|
1580
|
+
isSafeOrchestrationText(item.selected) &&
|
|
1581
|
+
isSafeOrchestrationText(item.reversibility)
|
|
1582
|
+
);
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
function isCheckpointBundle(value: unknown): boolean {
|
|
1586
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1587
|
+
const item = value as Record<string, unknown>;
|
|
1588
|
+
return (
|
|
1589
|
+
hasExactKeys(item, [
|
|
1590
|
+
"requestSummary",
|
|
1591
|
+
"requestRef",
|
|
1592
|
+
"acceptedPlanArtifactId",
|
|
1593
|
+
"contentRef",
|
|
1594
|
+
"contentHash",
|
|
1595
|
+
"testOutput",
|
|
1596
|
+
"driverSummary",
|
|
1597
|
+
"openRisks",
|
|
1598
|
+
"unresolvedFindingIds",
|
|
1599
|
+
]) &&
|
|
1600
|
+
isSafeOrchestrationText(item.requestSummary) &&
|
|
1601
|
+
(item.requestRef === undefined || isSafeId(item.requestRef)) &&
|
|
1602
|
+
isSafeId(item.acceptedPlanArtifactId) &&
|
|
1603
|
+
typeof item.contentRef === "string" &&
|
|
1604
|
+
/^(?!\/)(?!.*\.\.)[A-Za-z0-9._/@:-]{1,512}$/.test(item.contentRef) &&
|
|
1605
|
+
typeof item.contentHash === "string" &&
|
|
1606
|
+
SAFE_CONTENT_HASH.test(item.contentHash) &&
|
|
1607
|
+
isSafeOrchestrationText(item.testOutput) &&
|
|
1608
|
+
isSafeOrchestrationText(item.driverSummary) &&
|
|
1609
|
+
isSafeTextList(item.openRisks, 40) &&
|
|
1610
|
+
isSafeIdArray(item.unresolvedFindingIds, 40)
|
|
1611
|
+
);
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
function isCompletionTests(value: unknown): boolean {
|
|
1615
|
+
return (
|
|
1616
|
+
Array.isArray(value) &&
|
|
1617
|
+
value.length <= 40 &&
|
|
1618
|
+
value.every((test) => {
|
|
1619
|
+
if (!test || typeof test !== "object" || Array.isArray(test))
|
|
1620
|
+
return false;
|
|
1621
|
+
const item = test as Record<string, unknown>;
|
|
1622
|
+
return (
|
|
1623
|
+
hasExactKeys(item, ["name", "status", "evidence"]) &&
|
|
1624
|
+
isSafeOrchestrationText(item.name) &&
|
|
1625
|
+
["passed", "failed", "skipped"].includes(item.status as string) &&
|
|
1626
|
+
isSafeOrchestrationText(item.evidence)
|
|
1627
|
+
);
|
|
1628
|
+
})
|
|
1629
|
+
);
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
function isSafeTextList(value: unknown, max: number): boolean {
|
|
1633
|
+
return (
|
|
1634
|
+
Array.isArray(value) &&
|
|
1635
|
+
value.length <= max &&
|
|
1636
|
+
value.every((item) => isSafeOrchestrationText(item))
|
|
1637
|
+
);
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
function metadataKeysForOrchestrationKind(
|
|
1641
|
+
kind: NonNullable<MultiFrontierOrchestrationArtifact["kind"]>,
|
|
1642
|
+
): string[] {
|
|
1643
|
+
if (kind === "synthesis") {
|
|
1644
|
+
return ["agreed", "deterministicallyResolved", "reversibleResolution"];
|
|
1645
|
+
}
|
|
1646
|
+
if (kind === "checkpoint") return ["bundle"];
|
|
1647
|
+
if (kind === "cross_review" || kind === "watchdog_review") {
|
|
1648
|
+
return ["findings"];
|
|
1649
|
+
}
|
|
1650
|
+
if (kind === "finding_disposition") return ["dispositions"];
|
|
1651
|
+
if (kind === "completion") return ["tests", "proofRefs", "remainingRisks"];
|
|
1652
|
+
return [];
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
function containsUnsafeOrchestrationValue(
|
|
1656
|
+
value: unknown,
|
|
1657
|
+
depth: number,
|
|
1658
|
+
): boolean {
|
|
1659
|
+
if (depth > 8) return true;
|
|
1660
|
+
if (typeof value === "string") return !isSafeOrchestrationText(value);
|
|
1661
|
+
if (
|
|
1662
|
+
value === null ||
|
|
1663
|
+
typeof value === "boolean" ||
|
|
1664
|
+
(typeof value === "number" && Number.isFinite(value))
|
|
1665
|
+
) {
|
|
1666
|
+
return false;
|
|
1667
|
+
}
|
|
1668
|
+
if (Array.isArray(value)) {
|
|
1669
|
+
return (
|
|
1670
|
+
value.length > 40 ||
|
|
1671
|
+
value.some((item) => containsUnsafeOrchestrationValue(item, depth + 1))
|
|
1672
|
+
);
|
|
1673
|
+
}
|
|
1674
|
+
if (!value || typeof value !== "object") return true;
|
|
1675
|
+
const entries = Object.entries(value);
|
|
1676
|
+
return (
|
|
1677
|
+
entries.length > 40 ||
|
|
1678
|
+
entries.some(
|
|
1679
|
+
([key, item]) =>
|
|
1680
|
+
!isBoundedText(key, 160) ||
|
|
1681
|
+
/(token|secret|authorization|credential|password|email|organization|account)/i.test(
|
|
1682
|
+
key,
|
|
1683
|
+
) ||
|
|
1684
|
+
containsUnsafeOrchestrationValue(item, depth + 1),
|
|
1685
|
+
)
|
|
1686
|
+
);
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
function cloneOrchestrationArtifact(
|
|
1690
|
+
artifact: MultiFrontierOrchestrationArtifact,
|
|
1691
|
+
): MultiFrontierOrchestrationArtifact {
|
|
1692
|
+
return JSON.parse(
|
|
1693
|
+
JSON.stringify(artifact),
|
|
1694
|
+
) as MultiFrontierOrchestrationArtifact;
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
function isBoundedText(value: unknown, maxBytes: number): value is string {
|
|
1698
|
+
return (
|
|
1699
|
+
typeof value === "string" &&
|
|
1700
|
+
value.trim().length > 0 &&
|
|
1701
|
+
Buffer.byteLength(value, "utf-8") <= maxBytes
|
|
1702
|
+
);
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
function assertBoundedText(
|
|
1706
|
+
value: unknown,
|
|
1707
|
+
maxBytes: number,
|
|
1708
|
+
label: string,
|
|
1709
|
+
): void {
|
|
1710
|
+
if (!isBoundedText(value, maxBytes)) {
|
|
1711
|
+
throw new Error(`Invalid multi-frontier ${label}.`);
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
function assertRetentionLimits(
|
|
1716
|
+
limits: MultiFrontierParticipantEventRetentionLimits,
|
|
1717
|
+
): void {
|
|
1718
|
+
if (
|
|
1719
|
+
!isNonNegativeInteger(limits.maxEventCount) ||
|
|
1720
|
+
limits.maxEventCount < 1 ||
|
|
1721
|
+
!isNonNegativeInteger(limits.maxBytes) ||
|
|
1722
|
+
limits.maxBytes < 512
|
|
1723
|
+
) {
|
|
1724
|
+
throw new Error(
|
|
1725
|
+
"Invalid multi-frontier participant event retention limits.",
|
|
1726
|
+
);
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
function eventLineByteLength(
|
|
1731
|
+
event: PersistedMultiFrontierParticipantEvent,
|
|
1732
|
+
): number {
|
|
1733
|
+
return Buffer.byteLength(`${JSON.stringify(event)}\n`, "utf-8");
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
function isSafeId(value: unknown): value is string {
|
|
1737
|
+
return typeof value === "string" && SAFE_ID.test(value);
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
function isNonNegativeInteger(value: unknown): value is number {
|
|
1741
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0;
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
function assertParticipants(
|
|
1745
|
+
participants: MultiFrontierParticipantState[],
|
|
1746
|
+
): void {
|
|
1747
|
+
if (participants.length === 0) {
|
|
1748
|
+
throw new Error("A multi-frontier run needs at least one participant.");
|
|
1749
|
+
}
|
|
1750
|
+
const participantIds = new Set<string>();
|
|
1751
|
+
for (const participant of participants) {
|
|
1752
|
+
if (!isParticipant(participant))
|
|
1753
|
+
throw new Error("Invalid multi-frontier participant.");
|
|
1754
|
+
assertSafeId(participant.participantId, "participant id");
|
|
1755
|
+
if (participantIds.has(participant.participantId)) {
|
|
1756
|
+
throw new Error(
|
|
1757
|
+
`Duplicate multi-frontier participant id: ${participant.participantId}`,
|
|
1758
|
+
);
|
|
1759
|
+
}
|
|
1760
|
+
participantIds.add(participant.participantId);
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
function isParticipant(value: unknown): value is MultiFrontierParticipantState {
|
|
1765
|
+
if (!value || typeof value !== "object") return false;
|
|
1766
|
+
const participant = value as Partial<MultiFrontierParticipantState>;
|
|
1767
|
+
return (
|
|
1768
|
+
typeof participant.participantId === "string" &&
|
|
1769
|
+
SAFE_ID.test(participant.participantId) &&
|
|
1770
|
+
typeof participant.provider === "string" &&
|
|
1771
|
+
participant.provider.length > 0 &&
|
|
1772
|
+
typeof participant.runtime === "string" &&
|
|
1773
|
+
participant.runtime.length > 0 &&
|
|
1774
|
+
(participant.model === undefined ||
|
|
1775
|
+
typeof participant.model === "string") &&
|
|
1776
|
+
(participant.capabilities === undefined ||
|
|
1777
|
+
isStringArray(participant.capabilities)) &&
|
|
1778
|
+
(participant.sessionRef === undefined ||
|
|
1779
|
+
typeof participant.sessionRef === "string") &&
|
|
1780
|
+
(participant.role === "driver" || participant.role === "watchdog") &&
|
|
1781
|
+
isPermission(participant.permission) &&
|
|
1782
|
+
isParticipantStatus(participant.status)
|
|
1783
|
+
);
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
function areStoredParticipantsValid(
|
|
1787
|
+
value: unknown,
|
|
1788
|
+
): value is MultiFrontierParticipantState[] {
|
|
1789
|
+
if (
|
|
1790
|
+
!Array.isArray(value) ||
|
|
1791
|
+
value.length === 0 ||
|
|
1792
|
+
!value.every(isParticipant)
|
|
1793
|
+
) {
|
|
1794
|
+
return false;
|
|
1795
|
+
}
|
|
1796
|
+
return (
|
|
1797
|
+
new Set(value.map((participant) => participant.participantId)).size ===
|
|
1798
|
+
value.length
|
|
1799
|
+
);
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
function isStoredRunParticipantsAndDriverValid(
|
|
1803
|
+
participants: unknown,
|
|
1804
|
+
driver: unknown,
|
|
1805
|
+
): participants is MultiFrontierParticipantState[] {
|
|
1806
|
+
if (!areStoredParticipantsValid(participants) || !isDriver(driver)) {
|
|
1807
|
+
return false;
|
|
1808
|
+
}
|
|
1809
|
+
if (driver?.leaseState !== "active") {
|
|
1810
|
+
return participants.every(
|
|
1811
|
+
(participant) => participant.permission === "read_only",
|
|
1812
|
+
);
|
|
1813
|
+
}
|
|
1814
|
+
if (
|
|
1815
|
+
!participants.some(
|
|
1816
|
+
(participant) => participant.participantId === driver.participantId,
|
|
1817
|
+
)
|
|
1818
|
+
) {
|
|
1819
|
+
return false;
|
|
1820
|
+
}
|
|
1821
|
+
return participants.every((participant) => {
|
|
1822
|
+
if (participant.participantId !== driver.participantId) {
|
|
1823
|
+
return (
|
|
1824
|
+
participant.role === "watchdog" &&
|
|
1825
|
+
participant.permission === "read_only"
|
|
1826
|
+
);
|
|
1827
|
+
}
|
|
1828
|
+
return (
|
|
1829
|
+
participant.role === "driver" &&
|
|
1830
|
+
participant.permission === "workspace_write"
|
|
1831
|
+
);
|
|
1832
|
+
});
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
function isDriver(value: unknown): value is MultiFrontierDriverLease | null {
|
|
1836
|
+
if (value === null) return true;
|
|
1837
|
+
if (!value || typeof value !== "object") return false;
|
|
1838
|
+
const driver = value as Partial<MultiFrontierDriverLease>;
|
|
1839
|
+
return (
|
|
1840
|
+
typeof driver.participantId === "string" &&
|
|
1841
|
+
typeof driver.generation === "number" &&
|
|
1842
|
+
(driver.leaseState === "inactive" ||
|
|
1843
|
+
driver.leaseState === "active" ||
|
|
1844
|
+
driver.leaseState === "revoked")
|
|
1845
|
+
);
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
function isApproval(value: unknown): value is MultiFrontierApproval {
|
|
1849
|
+
if (!value || typeof value !== "object") return false;
|
|
1850
|
+
const approval = value as Partial<MultiFrontierApproval>;
|
|
1851
|
+
return (
|
|
1852
|
+
(approval.state === "not_required" ||
|
|
1853
|
+
approval.state === "pending" ||
|
|
1854
|
+
approval.state === "approved" ||
|
|
1855
|
+
approval.state === "rejected") &&
|
|
1856
|
+
(approval.proposalId === undefined ||
|
|
1857
|
+
typeof approval.proposalId === "string") &&
|
|
1858
|
+
(approval.reviewPacketId === undefined ||
|
|
1859
|
+
typeof approval.reviewPacketId === "string")
|
|
1860
|
+
);
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
function isRecovery(value: unknown): value is MultiFrontierRecovery {
|
|
1864
|
+
if (!value || typeof value !== "object") return false;
|
|
1865
|
+
const recovery = value as Partial<MultiFrontierRecovery>;
|
|
1866
|
+
return (
|
|
1867
|
+
isRecoveryReason(recovery.reason) &&
|
|
1868
|
+
typeof recovery.recoveredAt === "string" &&
|
|
1869
|
+
!Number.isNaN(Date.parse(recovery.recoveredAt)) &&
|
|
1870
|
+
isPhase(recovery.resumablePhase) &&
|
|
1871
|
+
(recovery.checkpointId === undefined ||
|
|
1872
|
+
typeof recovery.checkpointId === "string")
|
|
1873
|
+
);
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
function isPhase(value: unknown): value is MultiFrontierPhase {
|
|
1877
|
+
return (
|
|
1878
|
+
typeof value === "string" &&
|
|
1879
|
+
[
|
|
1880
|
+
"proposing",
|
|
1881
|
+
"cross_review",
|
|
1882
|
+
"converging",
|
|
1883
|
+
"awaiting_go",
|
|
1884
|
+
"implementing",
|
|
1885
|
+
"checkpoint_review",
|
|
1886
|
+
"paused",
|
|
1887
|
+
"completed",
|
|
1888
|
+
"failed",
|
|
1889
|
+
"canceled",
|
|
1890
|
+
].includes(value)
|
|
1891
|
+
);
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
function isParticipantStatus(
|
|
1895
|
+
value: unknown,
|
|
1896
|
+
): value is MultiFrontierParticipantStatus {
|
|
1897
|
+
return (
|
|
1898
|
+
value === "idle" ||
|
|
1899
|
+
value === "running" ||
|
|
1900
|
+
value === "waiting" ||
|
|
1901
|
+
value === "failed" ||
|
|
1902
|
+
value === "completed"
|
|
1903
|
+
);
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
function isPermission(
|
|
1907
|
+
value: unknown,
|
|
1908
|
+
): value is MultiFrontierParticipantPermission {
|
|
1909
|
+
return value === "read_only" || value === "workspace_write";
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
function isMatchingParticipantEvent(
|
|
1913
|
+
existing: PersistedMultiFrontierParticipantEvent,
|
|
1914
|
+
input: AppendMultiFrontierParticipantEventInput,
|
|
1915
|
+
): boolean {
|
|
1916
|
+
return (
|
|
1917
|
+
existing.collaborationId === input.collaborationId &&
|
|
1918
|
+
existing.participantId === input.participantId &&
|
|
1919
|
+
existing.permission === input.permission &&
|
|
1920
|
+
existing.generation === input.generation &&
|
|
1921
|
+
existing.status === input.status &&
|
|
1922
|
+
(input.createdAt === undefined || existing.createdAt === input.createdAt)
|
|
1923
|
+
);
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
function isStringArray(value: unknown): value is string[] {
|
|
1927
|
+
return (
|
|
1928
|
+
Array.isArray(value) && value.every((item) => typeof item === "string")
|
|
1929
|
+
);
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
function isRecoveryReason(
|
|
1933
|
+
value: unknown,
|
|
1934
|
+
): value is MultiFrontierRecoveryReason {
|
|
1935
|
+
return (
|
|
1936
|
+
value === "main_process_restarted" ||
|
|
1937
|
+
value === "driver_crashed" ||
|
|
1938
|
+
value === "watchdog_crashed" ||
|
|
1939
|
+
value === "app_quit" ||
|
|
1940
|
+
value === "canceled"
|
|
1941
|
+
);
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
function assertSafeId(value: string, label: string): void {
|
|
1945
|
+
if (!SAFE_ID.test(value)) throw new Error(`Invalid multi-frontier ${label}.`);
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
function assertTimestamp(value: string, label: string): void {
|
|
1949
|
+
if (Number.isNaN(Date.parse(value))) {
|
|
1950
|
+
throw new Error(`Invalid multi-frontier ${label}.`);
|
|
1951
|
+
}
|
|
1952
|
+
}
|