hostlet 0.0.0-stage → 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +233 -2
- package/bin/hostlet.js +61 -0
- package/console/app/api.js +1223 -0
- package/console/app/boot.js +165 -0
- package/console/app/cards.js +222 -0
- package/console/app/compose-quote.js +127 -0
- package/console/app/config-form.js +727 -0
- package/console/app/document-drafts.js +62 -0
- package/console/app/document-tools.mjs +67 -0
- package/console/app/documents.js +106 -0
- package/console/app/pages.js +6483 -0
- package/console/app/plugins.js +509 -0
- package/console/app/preview-tools.js +172 -0
- package/console/app/reference-labels.js +118 -0
- package/console/app/selection.js +372 -0
- package/console/app/store.js +57 -0
- package/console/app/text-anchor.js +26 -0
- package/console/app/topic-local.js +322 -0
- package/console/app/topic-nav.js +414 -0
- package/console/app/topic-status.js +109 -0
- package/console/app/views.js +43 -0
- package/console/apple-touch-icon.png +0 -0
- package/console/avatars/agy.svg +34 -0
- package/console/avatars/alhena.svg +36 -0
- package/console/avatars/castor.svg +38 -0
- package/console/avatars/claude.svg +34 -0
- package/console/avatars/codex.svg +34 -0
- package/console/avatars/devin.svg +34 -0
- package/console/avatars/echo.svg +34 -0
- package/console/avatars/kimi.svg +33 -0
- package/console/avatars/opencode.svg +33 -0
- package/console/avatars/pinion.svg +34 -0
- package/console/avatars/sprocket.svg +34 -0
- package/console/avatars/vela.svg +44 -0
- package/console/avatars/wasat.svg +38 -0
- package/console/clients/agy.svg +1 -0
- package/console/clients/claude.svg +1 -0
- package/console/clients/codex.svg +1 -0
- package/console/clients/devin.svg +1 -0
- package/console/clients/kimi.svg +1 -0
- package/console/clients/opencode.svg +1 -0
- package/console/favicon.ico +0 -0
- package/console/favicon.svg +16 -0
- package/console/index.html +99 -0
- package/console/pdl/engine/README.md +13 -0
- package/console/pdl/engine/anchor.js +195 -0
- package/console/pdl/engine/core.js +1340 -0
- package/console/pdl/engine/frame.js +1252 -0
- package/console/pdl/engine/i18n.js +67 -0
- package/console/pdl/engine/pdl-check.js +102 -0
- package/console/pdl/engine/pdl-doc.js +353 -0
- package/console/pdl/engine/pdl-view.js +280 -0
- package/console/pdl/engine/pdl.js +1064 -0
- package/console/pdl/engine/platform.js +18 -0
- package/console/pdl/engine/proj.js +279 -0
- package/console/pdl/engine/theme.js +176 -0
- package/console/pdl/engine/tree.js +171 -0
- package/console/pdl/engine/units.js +546 -0
- package/console/pdl/library/README.md +28 -0
- package/console/pdl/library/blocks.js +1512 -0
- package/console/pdl/library/buttons.js +86 -0
- package/console/pdl/library/capsules.js +130 -0
- package/console/pdl/library/charts.js +287 -0
- package/console/pdl/library/code.js +98 -0
- package/console/pdl/library/css/base.css +12 -0
- package/console/pdl/library/css/blocks.css +98 -0
- package/console/pdl/library/css/capsules.css +42 -0
- package/console/pdl/library/css/catalog-page.css +24 -0
- package/console/pdl/library/css/chat.css +100 -0
- package/console/pdl/library/css/composer-top.css +145 -0
- package/console/pdl/library/css/controls.css +195 -0
- package/console/pdl/library/css/drag.css +29 -0
- package/console/pdl/library/css/edit-layout.css +93 -0
- package/console/pdl/library/css/floating-window.css +30 -0
- package/console/pdl/library/css/hover.css +50 -0
- package/console/pdl/library/css/label-search.css +37 -0
- package/console/pdl/library/css/layers.css +43 -0
- package/console/pdl/library/css/library-parts.css +33 -0
- package/console/pdl/library/css/library.css +117 -0
- package/console/pdl/library/css/member-select.css +34 -0
- package/console/pdl/library/css/message.css +72 -0
- package/console/pdl/library/css/page.css +104 -0
- package/console/pdl/library/css/parts.css +338 -0
- package/console/pdl/library/css/responsive.css +40 -0
- package/console/pdl/library/css/roles.css +28 -0
- package/console/pdl/library/css/rows.css +231 -0
- package/console/pdl/library/css/settings-rows.css +37 -0
- package/console/pdl/library/css/shell.css +59 -0
- package/console/pdl/library/css/stream.css +296 -0
- package/console/pdl/library/css/theme-calculator.css +18 -0
- package/console/pdl/library/css/thumb-choice.css +69 -0
- package/console/pdl/library/css/tweaks.css +16 -0
- package/console/pdl/library/css/widgets.css +211 -0
- package/console/pdl/library/css/workbench.css +59 -0
- package/console/pdl/library/feedback.js +83 -0
- package/console/pdl/library/floating-window.mjs +100 -0
- package/console/pdl/library/fold.js +238 -0
- package/console/pdl/library/format.js +53 -0
- package/console/pdl/library/frames.js +123 -0
- package/console/pdl/library/icons.js +165 -0
- package/console/pdl/library/identity.js +149 -0
- package/console/pdl/library/inputs.js +801 -0
- package/console/pdl/library/label-search.js +214 -0
- package/console/pdl/library/markdown-text.js +115 -0
- package/console/pdl/library/markdown.js +150 -0
- package/console/pdl/library/media-viewer.js +293 -0
- package/console/pdl/library/member-select.mjs +32 -0
- package/console/pdl/library/message.js +105 -0
- package/console/pdl/library/motion.js +56 -0
- package/console/pdl/library/overlays.js +165 -0
- package/console/pdl/library/page.js +142 -0
- package/console/pdl/library/plugin-form.js +154 -0
- package/console/pdl/library/registry.js +198 -0
- package/console/pdl/library/rows.js +523 -0
- package/console/pdl/library/shell.js +151 -0
- package/console/pdl/library/stream.js +58 -0
- package/console/pdl/library/tabs.js +259 -0
- package/console/pdl/library/theme-calculator.js +300 -0
- package/console/pdl/library/widgets.js +114 -0
- package/console/pdl/load-order.json +74 -0
- package/console/pdl/platform/README.md +3 -0
- package/console/pdl/platform/rich-markdown.mjs +17 -0
- package/console/pdl/platform/web-links.js +26 -0
- package/console/pdl/platform/web.js +80 -0
- package/console/sdk-browser/mentions.d.mts +16 -0
- package/console/sdk-browser/mentions.mjs +84 -0
- package/console/theme/assets.js +21 -0
- package/console/theme/theme.json +9417 -0
- package/console/theme/tokens.json +444 -0
- package/dist/core/a2a.d.ts +288 -0
- package/dist/core/a2a.js +2197 -0
- package/dist/core/address.d.ts +34 -0
- package/dist/core/address.js +33 -0
- package/dist/core/approval-inputs.d.ts +17 -0
- package/dist/core/approval-inputs.js +70 -0
- package/dist/core/archive.d.ts +19 -0
- package/dist/core/archive.js +135 -0
- package/dist/core/attachments.d.ts +17 -0
- package/dist/core/attachments.js +143 -0
- package/dist/core/blocked-handoffs.d.ts +132 -0
- package/dist/core/blocked-handoffs.js +349 -0
- package/dist/core/config-schema.d.ts +124 -0
- package/dist/core/config-schema.js +192 -0
- package/dist/core/config.d.ts +117 -0
- package/dist/core/config.js +638 -0
- package/dist/core/disk-usage.d.ts +26 -0
- package/dist/core/disk-usage.js +83 -0
- package/dist/core/documents.d.ts +9 -0
- package/dist/core/documents.js +48 -0
- package/dist/core/entry.d.ts +316 -0
- package/dist/core/entry.js +711 -0
- package/dist/core/home.d.ts +76 -0
- package/dist/core/home.js +449 -0
- package/dist/core/i18n.d.ts +36 -0
- package/dist/core/i18n.js +458 -0
- package/dist/core/instances.d.ts +224 -0
- package/dist/core/instances.js +1272 -0
- package/dist/core/members.d.ts +190 -0
- package/dist/core/members.js +358 -0
- package/dist/core/mentions.d.ts +12 -0
- package/dist/core/mentions.js +49 -0
- package/dist/core/messages.d.ts +876 -0
- package/dist/core/messages.js +916 -0
- package/dist/core/notices.d.ts +88 -0
- package/dist/core/notices.js +54 -0
- package/dist/core/ops.d.ts +117 -0
- package/dist/core/ops.js +146 -0
- package/dist/core/package.d.ts +2 -0
- package/dist/core/package.js +14 -0
- package/dist/core/parts.d.ts +25 -0
- package/dist/core/parts.js +119 -0
- package/dist/core/plugins/catalog.d.ts +14 -0
- package/dist/core/plugins/catalog.js +54 -0
- package/dist/core/plugins/external.d.ts +7 -0
- package/dist/core/plugins/external.js +921 -0
- package/dist/core/plugins/index.d.ts +5 -0
- package/dist/core/plugins/index.js +51 -0
- package/dist/core/plugins/npm.d.ts +12 -0
- package/dist/core/plugins/npm.js +99 -0
- package/dist/core/plugins/plugin-manifest.d.ts +12 -0
- package/dist/core/plugins/plugin-manifest.js +231 -0
- package/dist/core/push.d.ts +22 -0
- package/dist/core/push.js +63 -0
- package/dist/core/resource.d.ts +77 -0
- package/dist/core/resource.js +48 -0
- package/dist/core/spawn.d.ts +12 -0
- package/dist/core/spawn.js +30 -0
- package/dist/core/storage-inventory.d.ts +118 -0
- package/dist/core/storage-inventory.js +279 -0
- package/dist/core/storage.d.ts +45 -0
- package/dist/core/storage.js +602 -0
- package/dist/core/store.d.ts +15 -0
- package/dist/core/store.js +33 -0
- package/dist/core/topic-index.d.ts +19 -0
- package/dist/core/topic-index.js +70 -0
- package/dist/core/topic-ops.d.ts +139 -0
- package/dist/core/topic-ops.js +507 -0
- package/dist/core/topic-status.d.ts +32 -0
- package/dist/core/topic-status.js +105 -0
- package/dist/core/topics.d.ts +327 -0
- package/dist/core/topics.js +786 -0
- package/dist/core/turn-clients.d.ts +1 -0
- package/dist/core/turn-clients.js +5 -0
- package/dist/core/types.d.ts +2866 -0
- package/dist/core/types.js +166 -0
- package/dist/core/util.d.ts +10 -0
- package/dist/core/util.js +47 -0
- package/dist/main.d.ts +12 -0
- package/dist/main.js +82 -0
- package/dist/plugins/adapter-acp/index.d.ts +3 -0
- package/dist/plugins/adapter-acp/index.js +57 -0
- package/dist/plugins/adapter-acp/plugin.yaml +100 -0
- package/dist/plugins/adapter-agy/command.d.ts +9 -0
- package/dist/plugins/adapter-agy/command.js +34 -0
- package/dist/plugins/adapter-agy/index.d.ts +5 -0
- package/dist/plugins/adapter-agy/index.js +65 -0
- package/dist/plugins/adapter-agy/quota.d.ts +2 -0
- package/dist/plugins/adapter-agy/quota.js +155 -0
- package/dist/plugins/adapter-agy/terminal.d.ts +6 -0
- package/dist/plugins/adapter-agy/terminal.js +132 -0
- package/dist/plugins/adapter-agy/version.d.ts +9 -0
- package/dist/plugins/adapter-agy/version.js +17 -0
- package/dist/plugins/adapter-claude/index.d.ts +43 -0
- package/dist/plugins/adapter-claude/index.js +412 -0
- package/dist/plugins/adapter-claude/quota.d.ts +14 -0
- package/dist/plugins/adapter-claude/quota.js +103 -0
- package/dist/plugins/adapter-codex/index.d.ts +4 -0
- package/dist/plugins/adapter-codex/index.js +688 -0
- package/dist/plugins/adapter-codex/responses-model.d.ts +9 -0
- package/dist/plugins/adapter-codex/responses-model.js +82 -0
- package/dist/plugins/adapter-kimi/index.d.ts +4 -0
- package/dist/plugins/adapter-kimi/index.js +51 -0
- package/dist/plugins/adapter-kimi/quota.d.ts +3 -0
- package/dist/plugins/adapter-kimi/quota.js +171 -0
- package/dist/plugins/adapter-opencode/index.d.ts +12 -0
- package/dist/plugins/adapter-opencode/index.js +64 -0
- package/dist/plugins/annotations/console/cards.css +189 -0
- package/dist/plugins/annotations/console/cards.mjs +439 -0
- package/dist/plugins/annotations/console/pdl.json +52 -0
- package/dist/plugins/annotations/console/view.mjs +241 -0
- package/dist/plugins/annotations/console/window.mjs +219 -0
- package/dist/plugins/annotations/followups.d.ts +51 -0
- package/dist/plugins/annotations/followups.js +112 -0
- package/dist/plugins/annotations/index.d.ts +3 -0
- package/dist/plugins/annotations/index.js +298 -0
- package/dist/plugins/annotations/plugin.yaml +3 -0
- package/dist/plugins/ask-choice/index.d.ts +9 -0
- package/dist/plugins/ask-choice/index.js +24 -0
- package/dist/plugins/ask-choice/plugin.yaml +2 -0
- package/dist/plugins/background/index.d.ts +2 -0
- package/dist/plugins/background/index.js +398 -0
- package/dist/plugins/background/plugin.yaml +7 -0
- package/dist/plugins/builtin.json +37 -0
- package/dist/plugins/cards/console/pdl.json +516 -0
- package/dist/plugins/cards/console/view.mjs +67 -0
- package/dist/plugins/cards/index.d.ts +8 -0
- package/dist/plugins/cards/index.js +627 -0
- package/dist/plugins/cards/plugin.yaml +3 -0
- package/dist/plugins/console/browser.d.ts +2 -0
- package/dist/plugins/console/browser.js +115 -0
- package/dist/plugins/console/console/pdl.json +38 -0
- package/dist/plugins/console/console/view.mjs +26 -0
- package/dist/plugins/console/index.d.ts +4 -0
- package/dist/plugins/console/index.js +94 -0
- package/dist/plugins/console/picker.d.ts +2 -0
- package/dist/plugins/console/picker.js +48 -0
- package/dist/plugins/console/plugin.yaml +3 -0
- package/dist/plugins/console/topic-view.d.ts +3 -0
- package/dist/plugins/console/topic-view.js +388 -0
- package/dist/plugins/handoff/index.d.ts +2 -0
- package/dist/plugins/handoff/index.js +147 -0
- package/dist/plugins/handoff/plugin.yaml +8 -0
- package/dist/plugins/host-api/index.d.ts +7 -0
- package/dist/plugins/host-api/index.js +310 -0
- package/dist/plugins/host-api/plugin.yaml +2 -0
- package/dist/plugins/host-api/signing.d.ts +63 -0
- package/dist/plugins/host-api/signing.js +427 -0
- package/dist/plugins/host-api/skills/host-ops/SKILL.md +28 -0
- package/dist/plugins/host-api/skills/hostlet-plugin-dev/SKILL.md +38 -0
- package/dist/plugins/inbox/index.d.ts +15 -0
- package/dist/plugins/inbox/index.js +161 -0
- package/dist/plugins/inbox/plugin.yaml +2 -0
- package/dist/plugins/keys/account-directories.d.ts +18 -0
- package/dist/plugins/keys/account-directories.js +86 -0
- package/dist/plugins/keys/account-storage.d.ts +18 -0
- package/dist/plugins/keys/account-storage.js +112 -0
- package/dist/plugins/keys/console/pdl.json +710 -0
- package/dist/plugins/keys/console/view.mjs +619 -0
- package/dist/plugins/keys/index.d.ts +7 -0
- package/dist/plugins/keys/index.js +842 -0
- package/dist/plugins/keys/login-link.d.ts +2 -0
- package/dist/plugins/keys/login-link.js +15 -0
- package/dist/plugins/keys/plugin.yaml +3 -0
- package/dist/plugins/keys/quota-history.d.ts +91 -0
- package/dist/plugins/keys/quota-history.js +420 -0
- package/dist/plugins/mcp/console/pdl.json +412 -0
- package/dist/plugins/mcp/console/view.mjs +207 -0
- package/dist/plugins/mcp/index.d.ts +7 -0
- package/dist/plugins/mcp/index.js +494 -0
- package/dist/plugins/mcp/plugin.yaml +3 -0
- package/dist/plugins/member-health/index.d.ts +2 -0
- package/dist/plugins/member-health/index.js +478 -0
- package/dist/plugins/member-health/plugin.yaml +2 -0
- package/dist/plugins/memory/capabilities.d.ts +10 -0
- package/dist/plugins/memory/capabilities.js +70 -0
- package/dist/plugins/memory/console/pdl.json +459 -0
- package/dist/plugins/memory/console/view.mjs +254 -0
- package/dist/plugins/memory/corpus.d.ts +60 -0
- package/dist/plugins/memory/corpus.js +521 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.d.ts +8 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.js +49 -0
- package/dist/plugins/memory/engines/fts-tree-text.d.ts +12 -0
- package/dist/plugins/memory/engines/fts-tree-text.js +93 -0
- package/dist/plugins/memory/engines/fts-tree.d.ts +4 -0
- package/dist/plugins/memory/engines/fts-tree.js +387 -0
- package/dist/plugins/memory/engines/search.d.ts +9 -0
- package/dist/plugins/memory/engines/search.js +35 -0
- package/dist/plugins/memory/index.d.ts +3 -0
- package/dist/plugins/memory/index.js +465 -0
- package/dist/plugins/memory/notes.d.ts +22 -0
- package/dist/plugins/memory/notes.js +140 -0
- package/dist/plugins/memory/plugin.yaml +23 -0
- package/dist/plugins/model-profiles/index.d.ts +2 -0
- package/dist/plugins/model-profiles/index.js +916 -0
- package/dist/plugins/model-profiles/plugin.yaml +13 -0
- package/dist/plugins/model-profiles/review-source.d.ts +11 -0
- package/dist/plugins/model-profiles/review-source.js +640 -0
- package/dist/plugins/model-profiles/rules.d.ts +130 -0
- package/dist/plugins/model-profiles/rules.js +729 -0
- package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +59 -0
- package/dist/plugins/model-profiles/sources.d.ts +61 -0
- package/dist/plugins/model-profiles/sources.js +375 -0
- package/dist/plugins/model-profiles/storage.d.ts +84 -0
- package/dist/plugins/model-profiles/storage.js +315 -0
- package/dist/plugins/model-profiles/types.d.ts +179 -0
- package/dist/plugins/model-profiles/types.js +12 -0
- package/dist/plugins/model-profiles/wakeup.d.ts +29 -0
- package/dist/plugins/model-profiles/wakeup.js +390 -0
- package/dist/plugins/models/index.d.ts +2 -0
- package/dist/plugins/models/index.js +63 -0
- package/dist/plugins/models/plugin.yaml +8 -0
- package/dist/plugins/ops/collector.d.ts +22 -0
- package/dist/plugins/ops/collector.js +48 -0
- package/dist/plugins/ops/config.d.ts +11 -0
- package/dist/plugins/ops/config.js +13 -0
- package/dist/plugins/ops/console/pdl.json +676 -0
- package/dist/plugins/ops/console/view.mjs +700 -0
- package/dist/plugins/ops/index.d.ts +3 -0
- package/dist/plugins/ops/index.js +20 -0
- package/dist/plugins/ops/journal.d.ts +7 -0
- package/dist/plugins/ops/journal.js +109 -0
- package/dist/plugins/ops/metrics.d.ts +3 -0
- package/dist/plugins/ops/metrics.js +81 -0
- package/dist/plugins/ops/plugin.yaml +63 -0
- package/dist/plugins/ops/samples.d.ts +54 -0
- package/dist/plugins/ops/samples.js +100 -0
- package/dist/plugins/ops/trace.d.ts +3 -0
- package/dist/plugins/ops/trace.js +104 -0
- package/dist/plugins/ops/usage.d.ts +2 -0
- package/dist/plugins/ops/usage.js +152 -0
- package/dist/plugins/plans/acceptance.d.ts +284 -0
- package/dist/plugins/plans/acceptance.js +247 -0
- package/dist/plugins/plans/blocked.d.ts +25 -0
- package/dist/plugins/plans/blocked.js +66 -0
- package/dist/plugins/plans/console/pdl.json +639 -0
- package/dist/plugins/plans/console/view.d.mts +2 -0
- package/dist/plugins/plans/console/view.mjs +855 -0
- package/dist/plugins/plans/dependencies.d.ts +5 -0
- package/dist/plugins/plans/dependencies.js +21 -0
- package/dist/plugins/plans/index.d.ts +72 -0
- package/dist/plugins/plans/index.js +2057 -0
- package/dist/plugins/plans/plugin.yaml +44 -0
- package/dist/plugins/plans/progress.d.ts +82 -0
- package/dist/plugins/plans/progress.js +516 -0
- package/dist/plugins/prompt/index.d.ts +8 -0
- package/dist/plugins/prompt/index.js +361 -0
- package/dist/plugins/prompt/plugin.yaml +2 -0
- package/dist/plugins/recovery/console/pdl.json +50 -0
- package/dist/plugins/recovery/console/view.mjs +46 -0
- package/dist/plugins/recovery/index.d.ts +9 -0
- package/dist/plugins/recovery/index.js +454 -0
- package/dist/plugins/recovery/plugin.yaml +9 -0
- package/dist/plugins/recovery/probe.d.ts +11 -0
- package/dist/plugins/recovery/probe.js +128 -0
- package/dist/plugins/restart/console/pdl.json +112 -0
- package/dist/plugins/restart/console/view.mjs +85 -0
- package/dist/plugins/restart/index.d.ts +10 -0
- package/dist/plugins/restart/index.js +669 -0
- package/dist/plugins/restart/plugin.yaml +9 -0
- package/dist/plugins/restart/scope.d.ts +6 -0
- package/dist/plugins/restart/scope.js +44 -0
- package/dist/plugins/schedule/console/pdl.json +696 -0
- package/dist/plugins/schedule/console/view.mjs +398 -0
- package/dist/plugins/schedule/events.d.ts +76 -0
- package/dist/plugins/schedule/events.js +158 -0
- package/dist/plugins/schedule/index.d.ts +32 -0
- package/dist/plugins/schedule/index.js +1199 -0
- package/dist/plugins/schedule/plugin.yaml +26 -0
- package/dist/plugins/schedule/when.d.ts +14 -0
- package/dist/plugins/schedule/when.js +83 -0
- package/dist/plugins/sessions/console/pdl.json +259 -0
- package/dist/plugins/sessions/console/view.mjs +355 -0
- package/dist/plugins/sessions/index.d.ts +3 -0
- package/dist/plugins/sessions/index.js +126 -0
- package/dist/plugins/sessions/participants.d.ts +28 -0
- package/dist/plugins/sessions/participants.js +83 -0
- package/dist/plugins/sessions/plugin.yaml +3 -0
- package/dist/plugins/signals/console/pdl.json +802 -0
- package/dist/plugins/signals/console/view.mjs +284 -0
- package/dist/plugins/signals/content.d.ts +31 -0
- package/dist/plugins/signals/content.js +151 -0
- package/dist/plugins/signals/index.d.ts +2 -0
- package/dist/plugins/signals/index.js +601 -0
- package/dist/plugins/signals/plugin.yaml +32 -0
- package/dist/plugins/signals/skills/signal-sources/SKILL.md +27 -0
- package/dist/plugins/skills/console/pdl.json +254 -0
- package/dist/plugins/skills/console/view.mjs +204 -0
- package/dist/plugins/skills/index.d.ts +11 -0
- package/dist/plugins/skills/index.js +567 -0
- package/dist/plugins/skills/install.d.ts +69 -0
- package/dist/plugins/skills/install.js +265 -0
- package/dist/plugins/skills/plugin.yaml +24 -0
- package/dist/plugins/skills/safety-scan.d.ts +17 -0
- package/dist/plugins/skills/safety-scan.js +78 -0
- package/dist/plugins/skills/skills/skill-ops/SKILL.md +29 -0
- package/dist/plugins/terminal/console/pdl.json +115 -0
- package/dist/plugins/terminal/console/view.mjs +178 -0
- package/dist/plugins/terminal/index.d.ts +3 -0
- package/dist/plugins/terminal/index.js +204 -0
- package/dist/plugins/terminal/plugin.yaml +2 -0
- package/dist/plugins/tools/index.d.ts +3 -0
- package/dist/plugins/tools/index.js +455 -0
- package/dist/plugins/tools/plugin.yaml +2 -0
- package/dist/plugins/tools/token.d.ts +61 -0
- package/dist/plugins/tools/token.js +179 -0
- package/dist/plugins/topic-tools/index.d.ts +9 -0
- package/dist/plugins/topic-tools/index.js +29 -0
- package/dist/plugins/topic-tools/plugin.yaml +2 -0
- package/dist/plugins/topic-tools/skills/topic-tidy/SKILL.md +108 -0
- package/dist/plugins/works/console/pdl.json +120 -0
- package/dist/plugins/works/console/view.mjs +91 -0
- package/dist/plugins/works/document-words.d.ts +50 -0
- package/dist/plugins/works/document-words.js +27 -0
- package/dist/plugins/works/editors.d.ts +3 -0
- package/dist/plugins/works/editors.js +162 -0
- package/dist/plugins/works/events.d.ts +58 -0
- package/dist/plugins/works/events.js +82 -0
- package/dist/plugins/works/files.d.ts +23 -0
- package/dist/plugins/works/files.js +53 -0
- package/dist/plugins/works/index.d.ts +9 -0
- package/dist/plugins/works/index.js +1088 -0
- package/dist/plugins/works/plugin.yaml +9 -0
- package/dist/plugins/works/preview.d.ts +10 -0
- package/dist/plugins/works/preview.js +30 -0
- package/dist/plugins/works/project.d.ts +3 -0
- package/dist/plugins/works/project.js +245 -0
- package/dist/plugins/works/resource.d.ts +28 -0
- package/dist/plugins/works/resource.js +71 -0
- package/dist/plugins/works/retention.d.ts +36 -0
- package/dist/plugins/works/retention.js +295 -0
- package/dist/plugins/works/skills/works-ops/SKILL.md +14 -0
- package/dist/plugins/works/viewers.d.ts +13 -0
- package/dist/plugins/works/viewers.js +87 -0
- package/dist/plugins/works/web/anchors.js +94 -0
- package/dist/plugins/works/web/document-edit.js +245 -0
- package/dist/plugins/works/web/preview-bridge.js +142 -0
- package/dist/plugins/works/web/reading-position.js +74 -0
- package/dist/plugins/works/web/view.html +1118 -0
- package/dist/runtime/runtime.d.ts +210 -0
- package/dist/runtime/runtime.js +338 -0
- package/dist/sdk/adapter-kit.d.ts +1 -0
- package/dist/sdk/adapter-kit.js +1 -0
- package/dist/sdk/client.d.ts +163 -0
- package/dist/sdk/client.js +43 -0
- package/dist/sdk/contracts.d.ts +1263 -0
- package/dist/sdk/contracts.js +1 -0
- package/dist/sdk/index.d.ts +57 -0
- package/dist/sdk/index.js +27 -0
- package/dist/sdk/source-choice.d.ts +40 -0
- package/dist/sdk/source-choice.js +217 -0
- package/dist/sdk/topic-text.d.ts +5 -0
- package/dist/sdk/topic-text.js +26 -0
- package/dist/sdk/transport.d.ts +12 -0
- package/dist/sdk/transport.js +34 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.d.ts +88 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.js +674 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.d.ts +18 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.js +39 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.d.ts +8 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.js +6 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.js +108 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.d.ts +3 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.js +4 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.js +84 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.d.ts +5 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.js +37 -0
- package/node_modules/@hostlet/adapter-kit/package.json +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.d.ts +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.js +270 -0
- package/node_modules/@hostlet/platform/dist/files.d.ts +24 -0
- package/node_modules/@hostlet/platform/dist/files.js +113 -0
- package/node_modules/@hostlet/platform/dist/index.d.ts +6 -0
- package/node_modules/@hostlet/platform/dist/index.js +4 -0
- package/node_modules/@hostlet/platform/dist/paths.d.ts +4 -0
- package/node_modules/@hostlet/platform/dist/paths.js +9 -0
- package/node_modules/@hostlet/platform/dist/process.d.ts +45 -0
- package/node_modules/@hostlet/platform/dist/process.js +297 -0
- package/node_modules/@hostlet/platform/package.json +14 -0
- package/package.json +60 -4
|
@@ -0,0 +1,916 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { address, ArgsError, array, HttpError, newId, object, OWNER_ID } from 'hostlet/sdk';
|
|
3
|
+
import { computeMeasured, demoteExpiredLines, emptyLines, familiesOverlap, hasVerifiedFamilyBootstrap, independentConfirmationCount, isQualifyingCrossFamilyObservation, sameStringArray, validateFamilyTagUpdate, validateProfileWrite, } from "./rules.js";
|
|
4
|
+
import { createSources, domainOfTopic, resolveHostLink } from "./sources.js";
|
|
5
|
+
import { ProfilesStore, renderProfileDetail, renderProfileMeta, renderProfileSummary, } from "./storage.js";
|
|
6
|
+
import { EXPIRY_CHECK_MS, RECENT_MODEL_MS, ROLES, SIGNS, WINDOW_DAYS, WINDOW_MS, } from "./types.js";
|
|
7
|
+
import { runWakeupCheck } from "./wakeup.js";
|
|
8
|
+
const string = { type: 'string' };
|
|
9
|
+
const number = { type: 'number' };
|
|
10
|
+
const boolean = { type: 'boolean' };
|
|
11
|
+
const profileLineSchema = object({
|
|
12
|
+
text: { ...string, description: '结论正文(不含证据编号)' },
|
|
13
|
+
role: { type: 'string', enum: [...ROLES], description: '观察角色' },
|
|
14
|
+
domain: { ...string, description: '领域主题编号(可选;填写时要求引用证据同领域,省略表示跨领域通用优势)' },
|
|
15
|
+
evidence: { ...array(string), description: '引用的观察记录编号列表' },
|
|
16
|
+
selfDescribed: boolean,
|
|
17
|
+
reason: string,
|
|
18
|
+
}, ['text']);
|
|
19
|
+
const profileLinesSchema = object({
|
|
20
|
+
strengths: { ...array(profileLineSchema), description: '擅长(最多 3 行)' },
|
|
21
|
+
cautions: { ...array(profileLineSchema), description: '注意(最多 3 行)' },
|
|
22
|
+
review: { ...array(profileLineSchema), description: '待复核(过期的结论或自述)' },
|
|
23
|
+
});
|
|
24
|
+
function parseSince(value) {
|
|
25
|
+
if (value === undefined || value === null || value === '')
|
|
26
|
+
return undefined;
|
|
27
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
28
|
+
return value;
|
|
29
|
+
if (typeof value === 'string') {
|
|
30
|
+
const trimmed = value.trim();
|
|
31
|
+
if (/^\d+$/.test(trimmed))
|
|
32
|
+
return Number(trimmed);
|
|
33
|
+
const parsed = Date.parse(trimmed);
|
|
34
|
+
if (Number.isFinite(parsed))
|
|
35
|
+
return parsed;
|
|
36
|
+
}
|
|
37
|
+
throw new ArgsError(`无效的时间参数 since:${String(value)}`);
|
|
38
|
+
}
|
|
39
|
+
export default function modelProfilesPlugin(home, ext) {
|
|
40
|
+
return {
|
|
41
|
+
name: 'model-profiles',
|
|
42
|
+
title: '模型画像',
|
|
43
|
+
about: '收集各模型的实测观察与跨系列判断,维护模型和客户端画像,辅助成员派活与挑选复核人。',
|
|
44
|
+
group: '成员',
|
|
45
|
+
needs: ['a2a', 'entry', 'instances', 'members', 'messages', 'models', 'topics'],
|
|
46
|
+
start(ctx) {
|
|
47
|
+
ctx.hook('topic.records', () => 'data'); // profiles live in their topic's data/
|
|
48
|
+
const a2a = ctx.get('a2a');
|
|
49
|
+
const entry = ctx.get('entry');
|
|
50
|
+
const members = ctx.get('members');
|
|
51
|
+
const messages = ctx.get('messages');
|
|
52
|
+
const models = ctx.get('models');
|
|
53
|
+
const topics = ctx.get('topics');
|
|
54
|
+
const pluginTopic = ext.topic();
|
|
55
|
+
const notifier = members.register(ctx, {
|
|
56
|
+
name: '模型画像',
|
|
57
|
+
handle: 'model-profiles',
|
|
58
|
+
icon: 'chart',
|
|
59
|
+
color: { primary: '#5b6ee1' },
|
|
60
|
+
});
|
|
61
|
+
const dataDir = home.path('data', ext.id);
|
|
62
|
+
const store = new ProfilesStore(pluginTopic.dir, dataDir);
|
|
63
|
+
const sources = createSources(store, { checkOnly: home.checkOnly });
|
|
64
|
+
const sourceKinds = new Map(sources.map((s) => [s.id, s.kind]));
|
|
65
|
+
const sourcesAvailability = () => Object.fromEntries(sources.map((s) => [s.id, s.available(ctx)]));
|
|
66
|
+
const observations = store.readObservationsIndex();
|
|
67
|
+
const wakeupState = store.readWakeupState();
|
|
68
|
+
const latestTurnModelByMember = new Map();
|
|
69
|
+
const preferredBaselineMember = new Map();
|
|
70
|
+
// Hydrate latestTurnModelByMember from existing turn observations.
|
|
71
|
+
for (const obs of observations.values()) {
|
|
72
|
+
if (obs.source !== 'turn' || !obs.model)
|
|
73
|
+
continue;
|
|
74
|
+
const prev = latestTurnModelByMember.get(obs.member);
|
|
75
|
+
if (!prev || obs.at > prev.at) {
|
|
76
|
+
latestTurnModelByMember.set(obs.member, { model: obs.model, at: obs.at });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const domainLabel = (id) => topics.get(id)?.title ?? id;
|
|
80
|
+
const normalizeModelKey = (key) => key.trim().toLowerCase();
|
|
81
|
+
const verifiedTagsByModel = new Map();
|
|
82
|
+
let resolverPreviewOverride = null;
|
|
83
|
+
const syncVerifiedTags = (records) => {
|
|
84
|
+
verifiedTagsByModel.clear();
|
|
85
|
+
for (const record of records) {
|
|
86
|
+
if (record.kind === 'model' && Array.isArray(record.verifiedFamilies) && record.verifiedFamilies.length) {
|
|
87
|
+
verifiedTagsByModel.set(normalizeModelKey(record.key), [...record.verifiedFamilies]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const formatRecord = (record, bootstrapped = hasVerifiedFamilyBootstrap(verifiedTagsByModel)) => {
|
|
92
|
+
const clean = {
|
|
93
|
+
key: record.key,
|
|
94
|
+
kind: record.kind,
|
|
95
|
+
...(record.kind === 'model' ? { families: record.families ?? [] } : {}),
|
|
96
|
+
...(record.kind === 'model' && record.verifiedFamilies?.length ? { verifiedFamilies: [...record.verifiedFamilies] } : {}),
|
|
97
|
+
...(record.kind === 'model' && record.pendingFamilies ? { pendingFamilies: record.pendingFamilies } : {}),
|
|
98
|
+
version: record.version,
|
|
99
|
+
updatedAt: record.updatedAt,
|
|
100
|
+
updatedBy: record.updatedBy,
|
|
101
|
+
updatedByModel: record.updatedByModel,
|
|
102
|
+
measured: record.measured,
|
|
103
|
+
lines: record.lines,
|
|
104
|
+
};
|
|
105
|
+
const meta = renderProfileMeta(clean);
|
|
106
|
+
const summary = renderProfileSummary(clean);
|
|
107
|
+
const detail = renderProfileDetail(clean, domainLabel, bootstrapped);
|
|
108
|
+
return { ...clean, meta, summary, detail };
|
|
109
|
+
};
|
|
110
|
+
const readBook = () => store.readBook(sourcesAvailability());
|
|
111
|
+
const findRecord = (kind, key) => {
|
|
112
|
+
const book = readBook();
|
|
113
|
+
const list = kind === 'model' ? book.models : book.clients;
|
|
114
|
+
return { book, list, record: list.find((item) => item.key === key) };
|
|
115
|
+
};
|
|
116
|
+
const ensureActiveTopic = () => {
|
|
117
|
+
const current = topics.get(pluginTopic.id);
|
|
118
|
+
if (!current || current.deletedAt !== null)
|
|
119
|
+
throw new HttpError(409, '模型画像主题不可用');
|
|
120
|
+
if (current.archivedAt !== null)
|
|
121
|
+
throw new HttpError(409, '模型画像主题已归档');
|
|
122
|
+
return current;
|
|
123
|
+
};
|
|
124
|
+
const emitChanged = (key, kind) => {
|
|
125
|
+
ctx.runtime.emit('profiles.changed', {
|
|
126
|
+
topicId: pluginTopic.id,
|
|
127
|
+
...(key ? { key } : {}),
|
|
128
|
+
...(kind ? { kind } : {}),
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
const refreshMeasuredFor = (keys, now = Date.now()) => {
|
|
132
|
+
const current = topics.get(pluginTopic.id);
|
|
133
|
+
if (!current || current.deletedAt !== null || current.archivedAt !== null)
|
|
134
|
+
return;
|
|
135
|
+
const allObs = [...observations.values()];
|
|
136
|
+
const book = readBook();
|
|
137
|
+
book.sources = sourcesAvailability();
|
|
138
|
+
let changed = false;
|
|
139
|
+
for (const modelKey of keys.models) {
|
|
140
|
+
const measured = computeMeasured(allObs, modelKey, 'model', now);
|
|
141
|
+
const idx = book.models.findIndex((item) => item.key === modelKey);
|
|
142
|
+
if (idx >= 0) {
|
|
143
|
+
const existing = book.models[idx];
|
|
144
|
+
book.models[idx] = formatRecord({ ...existing, families: models.familiesOf(modelKey), measured });
|
|
145
|
+
changed = true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
for (const clientKey of keys.clients) {
|
|
149
|
+
const measured = computeMeasured(allObs, clientKey, 'client', now);
|
|
150
|
+
const idx = book.clients.findIndex((item) => item.key === clientKey);
|
|
151
|
+
if (idx >= 0) {
|
|
152
|
+
const existing = book.clients[idx];
|
|
153
|
+
book.clients[idx] = formatRecord({ ...existing, measured });
|
|
154
|
+
changed = true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (changed) {
|
|
158
|
+
store.saveBook(book, observations.size);
|
|
159
|
+
emitChanged();
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const saveAllMeasured = (now = Date.now()) => {
|
|
163
|
+
const current = topics.get(pluginTopic.id);
|
|
164
|
+
if (!current || current.deletedAt !== null || current.archivedAt !== null)
|
|
165
|
+
return;
|
|
166
|
+
const allObs = [...observations.values()];
|
|
167
|
+
const book = readBook();
|
|
168
|
+
book.sources = sourcesAvailability();
|
|
169
|
+
book.models = book.models.map((item) => formatRecord({
|
|
170
|
+
...item,
|
|
171
|
+
families: models.familiesOf(item.key),
|
|
172
|
+
measured: computeMeasured(allObs, item.key, 'model', now),
|
|
173
|
+
}));
|
|
174
|
+
book.clients = book.clients.map((item) => formatRecord({
|
|
175
|
+
...item,
|
|
176
|
+
measured: computeMeasured(allObs, item.key, 'client', now),
|
|
177
|
+
}));
|
|
178
|
+
store.saveBook(book, observations.size);
|
|
179
|
+
emitChanged();
|
|
180
|
+
};
|
|
181
|
+
// Resolve a member's actual model following the 2-level rule (never falls back to configured alias).
|
|
182
|
+
const resolveMemberModel = (memberId, now = Date.now()) => {
|
|
183
|
+
const cached = latestTurnModelByMember.get(memberId);
|
|
184
|
+
if (cached?.model)
|
|
185
|
+
return { model: cached.model, source: 'latest_turn' };
|
|
186
|
+
const reported = models.memberModel(memberId);
|
|
187
|
+
if (reported?.model && now - reported.at <= RECENT_MODEL_MS) {
|
|
188
|
+
return { model: reported.model, source: 'recent_7d' };
|
|
189
|
+
}
|
|
190
|
+
return { model: null, source: 'configured_only' };
|
|
191
|
+
};
|
|
192
|
+
const callerLiveModel = (caller) => {
|
|
193
|
+
if (!caller.member)
|
|
194
|
+
return null;
|
|
195
|
+
if (caller.topicId) {
|
|
196
|
+
const live = a2a.live(caller.topicId).find((turn) => turn.memberId === caller.member.id);
|
|
197
|
+
if (live)
|
|
198
|
+
return live.model ?? models.turnModel(live.turnId) ?? null;
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
};
|
|
202
|
+
let stopped = false;
|
|
203
|
+
ctx.on('host.stopping', () => { stopped = true; });
|
|
204
|
+
let wakeupTimer;
|
|
205
|
+
const WAKEUP_SETTLE_MS = 30_000;
|
|
206
|
+
const scheduleWakeup = () => {
|
|
207
|
+
if (home.checkOnly || stopped || wakeupTimer)
|
|
208
|
+
return;
|
|
209
|
+
wakeupTimer = setTimeout(() => {
|
|
210
|
+
wakeupTimer = undefined;
|
|
211
|
+
if (stopped)
|
|
212
|
+
return;
|
|
213
|
+
void checkWakeup().catch((error) => {
|
|
214
|
+
if (!stopped)
|
|
215
|
+
ctx.runtime.onError('model-profiles wakeup', error);
|
|
216
|
+
});
|
|
217
|
+
}, WAKEUP_SETTLE_MS);
|
|
218
|
+
wakeupTimer.unref();
|
|
219
|
+
};
|
|
220
|
+
ctx.effect(() => {
|
|
221
|
+
stopped = true;
|
|
222
|
+
if (wakeupTimer) {
|
|
223
|
+
clearTimeout(wakeupTimer);
|
|
224
|
+
wakeupTimer = undefined;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
const recordObservations = (input) => {
|
|
228
|
+
const items = Array.isArray(input) ? input : [input];
|
|
229
|
+
if (!items.length)
|
|
230
|
+
return;
|
|
231
|
+
const touchedModels = new Set();
|
|
232
|
+
const touchedClients = new Set();
|
|
233
|
+
let indexChanged = false;
|
|
234
|
+
let shouldWake = false;
|
|
235
|
+
for (const obs of items) {
|
|
236
|
+
const prev = observations.get(obs.id);
|
|
237
|
+
const same = prev && JSON.stringify(prev) === JSON.stringify(obs);
|
|
238
|
+
if (!same) {
|
|
239
|
+
observations.set(obs.id, obs);
|
|
240
|
+
indexChanged = true;
|
|
241
|
+
}
|
|
242
|
+
if (obs.source === 'turn' && obs.model) {
|
|
243
|
+
const latest = latestTurnModelByMember.get(obs.member);
|
|
244
|
+
if (!latest || obs.at >= latest.at) {
|
|
245
|
+
latestTurnModelByMember.set(obs.member, { model: obs.model, at: obs.at });
|
|
246
|
+
}
|
|
247
|
+
if (!findRecord('model', obs.model).record) {
|
|
248
|
+
const ms = wakeupState.models[obs.model] ?? (wakeupState.models[obs.model] = {});
|
|
249
|
+
if (!ms.baselineRequested && !ms.pendingReason) {
|
|
250
|
+
ms.pendingReason = 'new_model';
|
|
251
|
+
preferredBaselineMember.set(obs.model, obs.member);
|
|
252
|
+
store.saveWakeupState(wakeupState);
|
|
253
|
+
shouldWake = true;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (obs.model && obs.source !== 'mismatch')
|
|
258
|
+
touchedModels.add(obs.model);
|
|
259
|
+
if (obs.client)
|
|
260
|
+
touchedClients.add(obs.client);
|
|
261
|
+
if (sourceKinds.get(obs.source) === 'judgment' && obs.model && obs.sign !== '·' && obs.judge) {
|
|
262
|
+
shouldWake = true;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (indexChanged) {
|
|
266
|
+
store.saveObservationsIndex(observations);
|
|
267
|
+
refreshMeasuredFor({ models: touchedModels, clients: touchedClients });
|
|
268
|
+
}
|
|
269
|
+
if (shouldWake)
|
|
270
|
+
scheduleWakeup();
|
|
271
|
+
};
|
|
272
|
+
const replaceSourceObservations = (sourceId, nextItems) => {
|
|
273
|
+
const touchedModels = new Set();
|
|
274
|
+
const touchedClients = new Set();
|
|
275
|
+
const nextIds = new Set();
|
|
276
|
+
let indexChanged = false;
|
|
277
|
+
let shouldWake = false;
|
|
278
|
+
for (const obs of observations.values()) {
|
|
279
|
+
if (obs.source !== sourceId)
|
|
280
|
+
continue;
|
|
281
|
+
if (obs.model && obs.source !== 'mismatch')
|
|
282
|
+
touchedModels.add(obs.model);
|
|
283
|
+
if (obs.client)
|
|
284
|
+
touchedClients.add(obs.client);
|
|
285
|
+
}
|
|
286
|
+
for (const obs of nextItems) {
|
|
287
|
+
nextIds.add(obs.id);
|
|
288
|
+
const prev = observations.get(obs.id);
|
|
289
|
+
const same = prev && JSON.stringify(prev) === JSON.stringify(obs);
|
|
290
|
+
if (!same) {
|
|
291
|
+
observations.set(obs.id, obs);
|
|
292
|
+
indexChanged = true;
|
|
293
|
+
if (sourceKinds.get(obs.source) === 'judgment' && obs.model && obs.sign !== '·' && obs.judge) {
|
|
294
|
+
shouldWake = true;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (obs.model && obs.source !== 'mismatch')
|
|
298
|
+
touchedModels.add(obs.model);
|
|
299
|
+
if (obs.client)
|
|
300
|
+
touchedClients.add(obs.client);
|
|
301
|
+
}
|
|
302
|
+
for (const [id, obs] of observations) {
|
|
303
|
+
if (obs.source === sourceId && !nextIds.has(id)) {
|
|
304
|
+
observations.delete(id);
|
|
305
|
+
indexChanged = true;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (indexChanged) {
|
|
309
|
+
store.saveObservationsIndex(observations);
|
|
310
|
+
refreshMeasuredFor({ models: touchedModels, clients: touchedClients });
|
|
311
|
+
}
|
|
312
|
+
if (shouldWake)
|
|
313
|
+
scheduleWakeup();
|
|
314
|
+
};
|
|
315
|
+
const checkExpiry = async (now = Date.now()) => {
|
|
316
|
+
const current = topics.get(pluginTopic.id);
|
|
317
|
+
if (!current || current.deletedAt !== null || current.archivedAt !== null)
|
|
318
|
+
return { demoted: [] };
|
|
319
|
+
const book = readBook();
|
|
320
|
+
const demoted = [];
|
|
321
|
+
const processList = (list, kind) => {
|
|
322
|
+
for (let i = 0; i < list.length; i++) {
|
|
323
|
+
const item = list[i];
|
|
324
|
+
const result = demoteExpiredLines(item.lines, observations, now);
|
|
325
|
+
if (!result.demoted)
|
|
326
|
+
continue;
|
|
327
|
+
const nextVersion = item.version + 1;
|
|
328
|
+
const updated = formatRecord({
|
|
329
|
+
...item,
|
|
330
|
+
version: nextVersion,
|
|
331
|
+
updatedAt: now,
|
|
332
|
+
updatedBy: 'plugin:model-profiles',
|
|
333
|
+
updatedByModel: null,
|
|
334
|
+
lines: result.next,
|
|
335
|
+
});
|
|
336
|
+
list[i] = updated;
|
|
337
|
+
store.appendHistory({
|
|
338
|
+
key: item.key,
|
|
339
|
+
kind,
|
|
340
|
+
version: nextVersion,
|
|
341
|
+
at: now,
|
|
342
|
+
by: 'plugin:model-profiles',
|
|
343
|
+
byModel: null,
|
|
344
|
+
lines: result.next,
|
|
345
|
+
});
|
|
346
|
+
demoted.push({ key: item.key, kind, count: result.demoted });
|
|
347
|
+
if (kind === 'model') {
|
|
348
|
+
const ms = wakeupState.models[item.key] ?? (wakeupState.models[item.key] = {});
|
|
349
|
+
ms.pendingReason = 'expired';
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
processList(book.models, 'model');
|
|
354
|
+
processList(book.clients, 'client');
|
|
355
|
+
if (demoted.length) {
|
|
356
|
+
book.sources = sourcesAvailability();
|
|
357
|
+
store.saveBook(book, observations.size);
|
|
358
|
+
store.saveWakeupState(wakeupState);
|
|
359
|
+
emitChanged();
|
|
360
|
+
}
|
|
361
|
+
return { demoted };
|
|
362
|
+
};
|
|
363
|
+
const checkWakeup = async (now = Date.now()) => runWakeupCheck({
|
|
364
|
+
ctx,
|
|
365
|
+
topic: pluginTopic,
|
|
366
|
+
notifier,
|
|
367
|
+
state: wakeupState,
|
|
368
|
+
saveState: () => store.saveWakeupState(wakeupState),
|
|
369
|
+
observations: () => observations,
|
|
370
|
+
sourceKinds,
|
|
371
|
+
modelProfile: (model) => findRecord('model', model).record,
|
|
372
|
+
allModelProfiles: () => readBook().models,
|
|
373
|
+
isFamilyBootstrapped: () => hasVerifiedFamilyBootstrap(verifiedTagsByModel),
|
|
374
|
+
resolveMemberModel,
|
|
375
|
+
preferredBaselineMember,
|
|
376
|
+
isStopped: () => stopped,
|
|
377
|
+
}, now);
|
|
378
|
+
const rebuild = async (since = Date.now() - WINDOW_MS) => {
|
|
379
|
+
observations.clear();
|
|
380
|
+
latestTurnModelByMember.clear();
|
|
381
|
+
for (const source of sources) {
|
|
382
|
+
if (!source.available(ctx))
|
|
383
|
+
continue;
|
|
384
|
+
const built = await source.rebuild(ctx, since);
|
|
385
|
+
for (const obs of built) {
|
|
386
|
+
observations.set(obs.id, obs);
|
|
387
|
+
if (obs.source === 'turn' && obs.model) {
|
|
388
|
+
const prev = latestTurnModelByMember.get(obs.member);
|
|
389
|
+
if (!prev || obs.at > prev.at) {
|
|
390
|
+
latestTurnModelByMember.set(obs.member, { model: obs.model, at: obs.at });
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
store.saveObservationsIndex(observations);
|
|
396
|
+
saveAllMeasured();
|
|
397
|
+
return { count: observations.size, sources: sourcesAvailability() };
|
|
398
|
+
};
|
|
399
|
+
// Hydrate verified model family tags and register them with the shared models service.
|
|
400
|
+
const initialBook = readBook();
|
|
401
|
+
syncVerifiedTags(initialBook.models);
|
|
402
|
+
ctx.effect(models.registerFamilyResolver((model) => (resolverPreviewOverride && resolverPreviewOverride.key === model
|
|
403
|
+
? resolverPreviewOverride.tags
|
|
404
|
+
: verifiedTagsByModel.get(model))));
|
|
405
|
+
// Initialize view.json and initial profiles.json for the plugin topic.
|
|
406
|
+
if (topics.get(pluginTopic.id)?.archivedAt === null) {
|
|
407
|
+
store.ensureView();
|
|
408
|
+
initialBook.models = initialBook.models.map((record) => {
|
|
409
|
+
const families = models.familiesOf(record.key);
|
|
410
|
+
return sameStringArray(record.families, families) ? record : formatRecord({ ...record, families });
|
|
411
|
+
});
|
|
412
|
+
initialBook.sources = sourcesAvailability();
|
|
413
|
+
store.saveBook(initialBook, observations.size);
|
|
414
|
+
}
|
|
415
|
+
// Start all sources.
|
|
416
|
+
for (const source of sources) {
|
|
417
|
+
const dispose = source.start(ctx, recordObservations, replaceSourceObservations);
|
|
418
|
+
if (dispose)
|
|
419
|
+
ctx.effect(dispose);
|
|
420
|
+
}
|
|
421
|
+
// Optional sources follow their services, whichever plugin provides them. A reload or a new provider replaces the instance.
|
|
422
|
+
const optional = ['review', 'plans'];
|
|
423
|
+
const instanceOf = (name) => ctx.runtime.has(name) ? ctx.get(name) : undefined;
|
|
424
|
+
let providers = optional.map(instanceOf);
|
|
425
|
+
ctx.on('plugin.changed', () => {
|
|
426
|
+
const next = optional.map(instanceOf);
|
|
427
|
+
if (next.some((one, i) => one !== providers[i]))
|
|
428
|
+
saveAllMeasured();
|
|
429
|
+
providers = next;
|
|
430
|
+
});
|
|
431
|
+
// Hourly expiry and deferred wakeup check (never triggers model turns by itself unless threshold met).
|
|
432
|
+
if (!home.checkOnly) {
|
|
433
|
+
const timer = setInterval(() => {
|
|
434
|
+
void checkExpiry().then(() => checkWakeup()).catch((error) => {
|
|
435
|
+
ctx.runtime.onError('model-profiles periodic check', error);
|
|
436
|
+
});
|
|
437
|
+
}, EXPIRY_CHECK_MS);
|
|
438
|
+
timer.unref();
|
|
439
|
+
ctx.effect(() => clearInterval(timer));
|
|
440
|
+
}
|
|
441
|
+
// Register skill and memory.sources.
|
|
442
|
+
ctx.hook('skills.dirs', () => fileURLToPath(new URL('./skills', import.meta.url)));
|
|
443
|
+
ctx.hook('memory.sources', () => ({
|
|
444
|
+
event: 'profiles.changed',
|
|
445
|
+
topics: () => [pluginTopic.id],
|
|
446
|
+
docs(topicId) {
|
|
447
|
+
if (topicId !== pluginTopic.id)
|
|
448
|
+
return [];
|
|
449
|
+
const book = readBook();
|
|
450
|
+
return [
|
|
451
|
+
...book.models.map((item) => ({
|
|
452
|
+
id: `model:${item.key}`,
|
|
453
|
+
title: `模型画像:${item.key}`,
|
|
454
|
+
text: item.detail,
|
|
455
|
+
})),
|
|
456
|
+
...book.clients.map((item) => ({
|
|
457
|
+
id: `client:${item.key}`,
|
|
458
|
+
title: `客户端画像:${item.key}`,
|
|
459
|
+
text: item.detail,
|
|
460
|
+
})),
|
|
461
|
+
];
|
|
462
|
+
},
|
|
463
|
+
}));
|
|
464
|
+
ctx.provide('modelProfiles', { rebuild, checkExpiry, checkWakeup });
|
|
465
|
+
// ── Operations (profiles group, agent: true) ──────────────────────────
|
|
466
|
+
ctx.effect(entry.group('profiles', '模型画像与客户端画像:查画像、查证据、记观察、写画像与重建索引'));
|
|
467
|
+
ctx.effect(entry.op({
|
|
468
|
+
name: 'profiles.get',
|
|
469
|
+
about: '查成员或模型的画像。都不传时查调用者自己(自感知);按成员查时返回实际模型、来源、模型画像和客户端画像。',
|
|
470
|
+
input: object({
|
|
471
|
+
member: { ...string, member: true, description: '成员编号或 @ 名' },
|
|
472
|
+
model: { ...string, description: '直接按实际模型 ID 查询' },
|
|
473
|
+
}),
|
|
474
|
+
http: ['GET', '/api/plugins/model-profiles/get'],
|
|
475
|
+
agent: true,
|
|
476
|
+
run({ member: memberArg, model: modelArg }, caller) {
|
|
477
|
+
if (modelArg && !memberArg) {
|
|
478
|
+
const key = modelArg.trim();
|
|
479
|
+
const found = findRecord('model', key).record;
|
|
480
|
+
const measured = found?.measured ?? computeMeasured([...observations.values()], key, 'model', Date.now());
|
|
481
|
+
return {
|
|
482
|
+
model: key,
|
|
483
|
+
families: models.familiesOf(key),
|
|
484
|
+
profile: found ?? null,
|
|
485
|
+
measured,
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
const targetId = memberArg ?? caller.member?.id;
|
|
489
|
+
if (!targetId)
|
|
490
|
+
throw new ArgsError('请传入 member 或 model');
|
|
491
|
+
const target = members.get(targetId);
|
|
492
|
+
if (!target)
|
|
493
|
+
throw new HttpError(404, `没有这个成员:${targetId}`);
|
|
494
|
+
const now = Date.now();
|
|
495
|
+
const resolved = resolveMemberModel(target.id, now);
|
|
496
|
+
const configuredRaw = typeof target.options?.model === 'string' && target.options.model.trim()
|
|
497
|
+
? target.options.model.trim()
|
|
498
|
+
: null;
|
|
499
|
+
const client = target.adapter ?? null;
|
|
500
|
+
const clientFound = client ? findRecord('client', client).record ?? null : null;
|
|
501
|
+
const clientMeasured = client
|
|
502
|
+
? (clientFound?.measured ?? computeMeasured([...observations.values()], client, 'client', now))
|
|
503
|
+
: null;
|
|
504
|
+
if (!resolved.model) {
|
|
505
|
+
return {
|
|
506
|
+
member: { id: target.id, name: target.name, handle: target.handle, adapter: client },
|
|
507
|
+
model: null,
|
|
508
|
+
modelSource: 'configured_only',
|
|
509
|
+
configuredModel: configuredRaw,
|
|
510
|
+
configuredNote: '配置值,可能是别名',
|
|
511
|
+
families: [],
|
|
512
|
+
profile: null,
|
|
513
|
+
client,
|
|
514
|
+
clientProfile: clientFound,
|
|
515
|
+
clientMeasured,
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
const modelFound = findRecord('model', resolved.model).record ?? null;
|
|
519
|
+
const modelMeasured = modelFound?.measured ?? computeMeasured([...observations.values()], resolved.model, 'model', now);
|
|
520
|
+
return {
|
|
521
|
+
member: { id: target.id, name: target.name, handle: target.handle, adapter: client },
|
|
522
|
+
model: resolved.model,
|
|
523
|
+
modelSource: resolved.source,
|
|
524
|
+
families: models.familiesOf(resolved.model),
|
|
525
|
+
profile: modelFound,
|
|
526
|
+
measured: modelMeasured,
|
|
527
|
+
client,
|
|
528
|
+
clientProfile: clientFound,
|
|
529
|
+
clientMeasured,
|
|
530
|
+
};
|
|
531
|
+
},
|
|
532
|
+
text(result) {
|
|
533
|
+
const lines = [];
|
|
534
|
+
if (result.member)
|
|
535
|
+
lines.push(`成员:${result.member.name} (@${result.member.handle})`);
|
|
536
|
+
if (result.model) {
|
|
537
|
+
const famText = result.families.length ? `(${result.families.join(' + ')})` : '';
|
|
538
|
+
lines.push(`实际模型:${result.model}${famText}${result.modelSource ? ` · 来源 ${result.modelSource}` : ''}`);
|
|
539
|
+
lines.push(result.profile ? result.profile.detail : '(该模型尚无画像)');
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
lines.push(`实际模型:未知(${result.configuredModel ? `配置值:${result.configuredModel},${result.configuredNote}` : '无配置值'})`);
|
|
543
|
+
}
|
|
544
|
+
if (result.client) {
|
|
545
|
+
lines.push('');
|
|
546
|
+
lines.push(result.clientProfile ? result.clientProfile.detail : `客户端 \`${result.client}\` 尚无画像`);
|
|
547
|
+
}
|
|
548
|
+
return lines.join('\n');
|
|
549
|
+
},
|
|
550
|
+
}));
|
|
551
|
+
ctx.effect(entry.op({
|
|
552
|
+
name: 'profiles.evidence',
|
|
553
|
+
about: '按模型或客户端列出观察记录,并返回各观察来源当前是否可用。',
|
|
554
|
+
input: object({
|
|
555
|
+
model: { ...string, description: '实际模型 ID' },
|
|
556
|
+
client: { ...string, description: '客户端适配器名' },
|
|
557
|
+
since: { description: '起始时间(毫秒时间戳或 ISO 日期)' },
|
|
558
|
+
source: { ...string, description: '按来源过滤:turn / mismatch / plan / member / review' },
|
|
559
|
+
limit: { ...number, description: '最多返回条数,默认 100' },
|
|
560
|
+
}),
|
|
561
|
+
http: ['GET', '/api/plugins/model-profiles/evidence'],
|
|
562
|
+
agent: true,
|
|
563
|
+
run({ model, client, since, source, limit = 100 }) {
|
|
564
|
+
const modelKey = typeof model === 'string' && model.trim() ? model.trim() : null;
|
|
565
|
+
const clientKey = typeof client === 'string' && client.trim() ? client.trim() : null;
|
|
566
|
+
const sourceKey = typeof source === 'string' && source.trim() ? source.trim() : null;
|
|
567
|
+
if (!modelKey && !clientKey && !sourceKey)
|
|
568
|
+
throw new ArgsError('请传入 model、client 或 source');
|
|
569
|
+
const sinceMs = parseSince(since);
|
|
570
|
+
const cap = Math.max(1, Math.min(500, Number(limit) || 100));
|
|
571
|
+
const list = [...observations.values()]
|
|
572
|
+
.filter((obs) => {
|
|
573
|
+
if (modelKey && obs.model !== modelKey)
|
|
574
|
+
return false;
|
|
575
|
+
if (clientKey && obs.client !== clientKey)
|
|
576
|
+
return false;
|
|
577
|
+
if (sinceMs !== undefined && obs.at < sinceMs)
|
|
578
|
+
return false;
|
|
579
|
+
if (sourceKey && obs.source !== sourceKey)
|
|
580
|
+
return false;
|
|
581
|
+
return true;
|
|
582
|
+
})
|
|
583
|
+
.sort((a, b) => b.at - a.at || b.id.localeCompare(a.id))
|
|
584
|
+
.slice(0, cap);
|
|
585
|
+
return {
|
|
586
|
+
model: modelKey,
|
|
587
|
+
client: clientKey,
|
|
588
|
+
sources: sourcesAvailability(),
|
|
589
|
+
observations: list,
|
|
590
|
+
};
|
|
591
|
+
},
|
|
592
|
+
}));
|
|
593
|
+
ctx.effect(entry.op({
|
|
594
|
+
name: 'profiles.observe',
|
|
595
|
+
about: '成员手记一条判断类观察。必须带宿主内可打开的证据地址 link;计入门槛时需带 plan。双方模型由插件从回合记录自动取得。',
|
|
596
|
+
input: object({
|
|
597
|
+
member: { ...string, member: true, description: '被观察的成员编号或 @ 名' },
|
|
598
|
+
role: { type: 'string', enum: [...ROLES], description: '观察角色' },
|
|
599
|
+
kind: { ...string, description: '观察分类,如 过度防御、改动越界、亮点 等' },
|
|
600
|
+
sign: { type: 'string', enum: [...SIGNS], description: '正面 + / 负面 - / 中性 ·' },
|
|
601
|
+
link: { ...string, description: '证据地址(如 #chat-<主题>/<消息>、#plans/<编号> 或 res:...)' },
|
|
602
|
+
note: { ...string, description: '观察说明正文' },
|
|
603
|
+
plan: { ...string, description: '所属规划编号(作为 workId);省略则不计入门槛' },
|
|
604
|
+
}, ['member', 'role', 'kind', 'sign', 'link', 'note']),
|
|
605
|
+
http: ['POST', '/api/plugins/model-profiles/observe'],
|
|
606
|
+
agent: true,
|
|
607
|
+
async run(args, caller) {
|
|
608
|
+
ensureActiveTopic();
|
|
609
|
+
const target = members.get(args.member);
|
|
610
|
+
if (!target)
|
|
611
|
+
throw new HttpError(404, `没有这个成员:${args.member}`);
|
|
612
|
+
const kind = args.kind.trim();
|
|
613
|
+
const note = args.note.trim();
|
|
614
|
+
if (!kind)
|
|
615
|
+
throw new ArgsError('kind 不能为空');
|
|
616
|
+
if (!note)
|
|
617
|
+
throw new ArgsError('note 不能为空');
|
|
618
|
+
const resolved = await resolveHostLink(args.link, { ctx, topics, messages, entry });
|
|
619
|
+
// Verify plan if supplied; require the evidence topic to match the plan's home or work topic.
|
|
620
|
+
let workId = null;
|
|
621
|
+
let planTopicId;
|
|
622
|
+
if (args.plan !== undefined && args.plan.trim()) {
|
|
623
|
+
const planId = args.plan.trim();
|
|
624
|
+
if (!ctx.runtime.has('plans'))
|
|
625
|
+
throw new ArgsError('规划插件未启用,无法核对 plan');
|
|
626
|
+
const allPlans = await entry.invoke('plans.list', { closed: true });
|
|
627
|
+
const foundPlan = allPlans.find((p) => p.id === planId);
|
|
628
|
+
if (!foundPlan)
|
|
629
|
+
throw new ArgsError(`没有这条规划:${planId}`);
|
|
630
|
+
const matchesPlanTopic = !resolved.topicId
|
|
631
|
+
|| resolved.topicId === foundPlan.topicId
|
|
632
|
+
|| (!!foundPlan.at && resolved.topicId === foundPlan.at);
|
|
633
|
+
workId = matchesPlanTopic ? planId : null;
|
|
634
|
+
if (matchesPlanTopic)
|
|
635
|
+
planTopicId = foundPlan.at ?? foundPlan.topicId;
|
|
636
|
+
}
|
|
637
|
+
// Determine observed member's model strictly from the turn that produced the linked message.
|
|
638
|
+
let observedModel = null;
|
|
639
|
+
if (resolved.topicId && resolved.messageId) {
|
|
640
|
+
const topicTurns = a2a.turns(resolved.topicId, { limit: 200 });
|
|
641
|
+
const matchedTurn = (resolved.message?.turnId
|
|
642
|
+
? a2a.turns(resolved.topicId, { turnId: resolved.message.turnId })[0]
|
|
643
|
+
: undefined)
|
|
644
|
+
?? topicTurns.find((t) => t.replyId === resolved.messageId);
|
|
645
|
+
if (matchedTurn) {
|
|
646
|
+
if (matchedTurn.memberId !== target.id) {
|
|
647
|
+
throw new ArgsError(`证据消息 ${resolved.messageId} 属于成员 ${matchedTurn.memberId} 的回合,与指定的 member(${target.id})不符`);
|
|
648
|
+
}
|
|
649
|
+
observedModel = matchedTurn.model ?? null;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
const judgeId = caller.member?.id ?? OWNER_ID;
|
|
653
|
+
const judgeModel = callerLiveModel(caller);
|
|
654
|
+
const domainTopic = resolved.topicId ?? planTopicId ?? caller.topicId;
|
|
655
|
+
const domain = domainTopic ? domainOfTopic(topics, domainTopic) : '';
|
|
656
|
+
const obs = {
|
|
657
|
+
id: `member:${newId('obs')}`,
|
|
658
|
+
source: 'member',
|
|
659
|
+
at: Date.now(),
|
|
660
|
+
member: target.id,
|
|
661
|
+
model: observedModel,
|
|
662
|
+
client: target.adapter ?? null,
|
|
663
|
+
role: args.role,
|
|
664
|
+
kind,
|
|
665
|
+
sign: args.sign,
|
|
666
|
+
domain,
|
|
667
|
+
link: resolved.canonical,
|
|
668
|
+
note,
|
|
669
|
+
workId,
|
|
670
|
+
judge: { member: judgeId, model: judgeModel },
|
|
671
|
+
};
|
|
672
|
+
store.appendMemberObservation(obs);
|
|
673
|
+
recordObservations(obs);
|
|
674
|
+
return obs;
|
|
675
|
+
},
|
|
676
|
+
text: (obs) => `已记录观察 \`${obs.id}\`(模型:${obs.model ?? '未知'},工作项:${obs.workId ?? '无,不计入门槛'})。`,
|
|
677
|
+
}));
|
|
678
|
+
ctx.effect(entry.op({
|
|
679
|
+
name: 'profiles.write',
|
|
680
|
+
about: '更新指定模型或客户端画像的「擅长」「注意」「待复核」三栏,或为模型画像打/确认所属系列标签(families)。按版本乐观锁与跨系列规则校验,写入历史审计日志。',
|
|
681
|
+
input: object({
|
|
682
|
+
model: { ...string, description: '目标实际模型 ID(与 client 二选一)' },
|
|
683
|
+
client: { ...string, description: '目标客户端适配器名(与 model 二选一)' },
|
|
684
|
+
lines: profileLinesSchema,
|
|
685
|
+
families: { ...array(string), description: '模型所属系列标签(仅 model 画像可用,支持复合模型多系列,如 ["anthropic", "cognition"];非机主须经 2 位互不重叠的跨系列成员确认后生效)' },
|
|
686
|
+
baseVersion: { ...number, description: '当前版本号(新建传 0)' },
|
|
687
|
+
notice: { ...string, description: '回应的画像唤醒通知消息编号(msg_…)。写入成功后该通知列出的观察记为已审;不传时只确认本次引用的观察' },
|
|
688
|
+
}, ['baseVersion']),
|
|
689
|
+
http: ['POST', '/api/plugins/model-profiles/write'],
|
|
690
|
+
agent: true,
|
|
691
|
+
run({ model, client, lines, families, baseVersion, notice }, caller) {
|
|
692
|
+
ensureActiveTopic();
|
|
693
|
+
const modelKey = typeof model === 'string' && model.trim() ? model.trim() : undefined;
|
|
694
|
+
const clientKey = typeof client === 'string' && client.trim() ? client.trim() : undefined;
|
|
695
|
+
if ((modelKey && clientKey) || (!modelKey && !clientKey)) {
|
|
696
|
+
throw new ArgsError('model 和 client 必须二选一');
|
|
697
|
+
}
|
|
698
|
+
if (lines === undefined && families === undefined) {
|
|
699
|
+
throw new ArgsError('lines 和 families 不能同时为空');
|
|
700
|
+
}
|
|
701
|
+
const kind = modelKey ? 'model' : 'client';
|
|
702
|
+
if (kind === 'client' && families !== undefined) {
|
|
703
|
+
throw new ArgsError('客户端画像不支持设置 families');
|
|
704
|
+
}
|
|
705
|
+
const key = (modelKey ?? clientKey);
|
|
706
|
+
const now = Date.now();
|
|
707
|
+
const callerId = caller.member?.id ?? OWNER_ID;
|
|
708
|
+
const callerModel = caller.member
|
|
709
|
+
? (callerLiveModel(caller) ?? resolveMemberModel(caller.member.id, now).model)
|
|
710
|
+
: null;
|
|
711
|
+
const noticeId = typeof notice === 'string' && notice.trim() ? notice.trim() : undefined;
|
|
712
|
+
const answered = noticeId ? wakeupState.models[key]?.notices?.[noticeId] : undefined;
|
|
713
|
+
if (noticeId) {
|
|
714
|
+
if (kind !== 'model')
|
|
715
|
+
throw new ArgsError('notice 只用于模型画像');
|
|
716
|
+
if (lines === undefined)
|
|
717
|
+
throw new ArgsError('回应通知要传 lines:审过这一批后写入的三栏(不改就原样传回),只打系列标签时不要带 notice');
|
|
718
|
+
if (!answered)
|
|
719
|
+
throw new ArgsError(`通知 ${noticeId} 不是模型 ${key} 待回应的画像唤醒通知`);
|
|
720
|
+
if (now - answered.at > WINDOW_MS)
|
|
721
|
+
throw new ArgsError(`通知 ${noticeId} 已超过 ${WINDOW_DAYS} 天,不能再凭它写回;不带 notice 写入只确认引用的观察`);
|
|
722
|
+
// Anyone eligible to judge this model may answer a notice, so handed-over work can be settled; the
|
|
723
|
+
// recipient stays the delivery record and the write is attributed to whoever actually wrote it.
|
|
724
|
+
if (callerId !== OWNER_ID) {
|
|
725
|
+
const targetFamilies = models.familiesOf(key);
|
|
726
|
+
const callerFamilies = models.familiesOf(callerModel);
|
|
727
|
+
const self = !!callerModel && callerModel.trim().toLowerCase() === key.trim().toLowerCase();
|
|
728
|
+
if (self || !callerFamilies.length || !targetFamilies.length || familiesOverlap(callerFamilies, targetFamilies)) {
|
|
729
|
+
throw new ArgsError(`回应通知 ${noticeId} 需要调用者当前模型与 ${key} 的系列都已核实且互不重叠`);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
const { book, list, record: current } = findRecord(kind, key);
|
|
734
|
+
const inputLines = lines !== undefined
|
|
735
|
+
? {
|
|
736
|
+
strengths: (lines.strengths ?? []),
|
|
737
|
+
cautions: (lines.cautions ?? []),
|
|
738
|
+
review: (lines.review ?? []),
|
|
739
|
+
}
|
|
740
|
+
: (current?.lines ?? emptyLines());
|
|
741
|
+
const validated = validateProfileWrite({
|
|
742
|
+
kind,
|
|
743
|
+
key,
|
|
744
|
+
lines: inputLines,
|
|
745
|
+
baseVersion,
|
|
746
|
+
current,
|
|
747
|
+
observations,
|
|
748
|
+
sourceKinds,
|
|
749
|
+
familiesOf: (m) => models.familiesOf(m),
|
|
750
|
+
callerId,
|
|
751
|
+
callerModel,
|
|
752
|
+
now,
|
|
753
|
+
});
|
|
754
|
+
const familyTag = kind === 'model'
|
|
755
|
+
? validateFamilyTagUpdate({
|
|
756
|
+
key,
|
|
757
|
+
inputFamilies: families,
|
|
758
|
+
current,
|
|
759
|
+
bootstrapped: hasVerifiedFamilyBootstrap(verifiedTagsByModel),
|
|
760
|
+
familiesOf: (m) => models.familiesOf(m),
|
|
761
|
+
callerId,
|
|
762
|
+
callerModel,
|
|
763
|
+
now,
|
|
764
|
+
})
|
|
765
|
+
: undefined;
|
|
766
|
+
// Compute effective families and bootstrap state without mutating verifiedTagsByModel until saveBook succeeds.
|
|
767
|
+
let effectiveFamilies;
|
|
768
|
+
let nextBootstrapped = hasVerifiedFamilyBootstrap(verifiedTagsByModel);
|
|
769
|
+
if (kind === 'model') {
|
|
770
|
+
const norm = normalizeModelKey(key);
|
|
771
|
+
const nextTags = familyTag?.verifiedFamilies?.length ? [...familyTag.verifiedFamilies] : undefined;
|
|
772
|
+
const nextVerifiedMap = new Map(verifiedTagsByModel);
|
|
773
|
+
if (nextTags)
|
|
774
|
+
nextVerifiedMap.set(norm, nextTags);
|
|
775
|
+
else
|
|
776
|
+
nextVerifiedMap.delete(norm);
|
|
777
|
+
nextBootstrapped = hasVerifiedFamilyBootstrap(nextVerifiedMap);
|
|
778
|
+
resolverPreviewOverride = { key: norm, tags: nextTags };
|
|
779
|
+
try {
|
|
780
|
+
effectiveFamilies = models.familiesOf(key);
|
|
781
|
+
}
|
|
782
|
+
finally {
|
|
783
|
+
resolverPreviewOverride = null;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
const nextVersion = (current?.version ?? 0) + 1;
|
|
787
|
+
const measured = computeMeasured([...observations.values()], key, kind, now);
|
|
788
|
+
const nextRecord = formatRecord({
|
|
789
|
+
key,
|
|
790
|
+
kind,
|
|
791
|
+
...(kind === 'model' ? {
|
|
792
|
+
families: effectiveFamilies,
|
|
793
|
+
verifiedFamilies: familyTag?.verifiedFamilies,
|
|
794
|
+
pendingFamilies: familyTag?.pendingFamilies,
|
|
795
|
+
} : {}),
|
|
796
|
+
version: nextVersion,
|
|
797
|
+
updatedAt: now,
|
|
798
|
+
updatedBy: callerId,
|
|
799
|
+
updatedByModel: callerModel,
|
|
800
|
+
measured,
|
|
801
|
+
lines: validated,
|
|
802
|
+
}, nextBootstrapped);
|
|
803
|
+
const idx = list.findIndex((item) => item.key === key);
|
|
804
|
+
if (idx >= 0)
|
|
805
|
+
list[idx] = nextRecord;
|
|
806
|
+
else
|
|
807
|
+
list.push(nextRecord);
|
|
808
|
+
book.sources = sourcesAvailability();
|
|
809
|
+
store.saveBook(book, observations.size);
|
|
810
|
+
if (kind === 'model') {
|
|
811
|
+
const norm = normalizeModelKey(key);
|
|
812
|
+
if (familyTag?.verifiedFamilies?.length) {
|
|
813
|
+
verifiedTagsByModel.set(norm, [...familyTag.verifiedFamilies]);
|
|
814
|
+
}
|
|
815
|
+
else {
|
|
816
|
+
verifiedTagsByModel.delete(norm);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
store.appendHistory({
|
|
820
|
+
key,
|
|
821
|
+
kind,
|
|
822
|
+
version: nextVersion,
|
|
823
|
+
at: now,
|
|
824
|
+
by: callerId,
|
|
825
|
+
byModel: callerModel,
|
|
826
|
+
lines: validated,
|
|
827
|
+
...(kind === 'model' ? {
|
|
828
|
+
families: effectiveFamilies,
|
|
829
|
+
...(familyTag?.verifiedFamilies?.length ? { verifiedFamilies: familyTag.verifiedFamilies } : {}),
|
|
830
|
+
...(familyTag?.pendingFamilies ? { pendingFamilies: familyTag.pendingFamilies } : {}),
|
|
831
|
+
} : {}),
|
|
832
|
+
});
|
|
833
|
+
if (kind === 'model') {
|
|
834
|
+
const ms = wakeupState.models[key] ?? (wakeupState.models[key] = {});
|
|
835
|
+
if (lines !== undefined) {
|
|
836
|
+
const targetFamilies = effectiveFamilies ?? models.familiesOf(key);
|
|
837
|
+
const callerFamilies = models.familiesOf(callerModel);
|
|
838
|
+
const isSelfModel = !!callerModel && callerModel.trim().toLowerCase() === key.trim().toLowerCase();
|
|
839
|
+
const isCrossFamilyOrOwner = callerId === OWNER_ID || (!isSelfModel
|
|
840
|
+
&& callerFamilies.length > 0
|
|
841
|
+
&& targetFamilies.length > 0
|
|
842
|
+
&& !familiesOverlap(callerFamilies, targetFamilies));
|
|
843
|
+
if (isCrossFamilyOrOwner) {
|
|
844
|
+
const cutoff = now - WINDOW_MS;
|
|
845
|
+
ms.lastRewrittenAt = now;
|
|
846
|
+
// Reviewed = what the answered notice showed plus what this write cites; nothing the writer never saw.
|
|
847
|
+
const seen = new Set([
|
|
848
|
+
...(ms.reviewedEvidenceIds ?? []),
|
|
849
|
+
...(answered?.ids ?? []),
|
|
850
|
+
...validated.strengths.flatMap((line) => line.evidence),
|
|
851
|
+
...validated.cautions.flatMap((line) => line.evidence),
|
|
852
|
+
]);
|
|
853
|
+
ms.reviewedEvidenceIds = [...observations.values()]
|
|
854
|
+
.filter((obs) => seen.has(obs.id) && isQualifyingCrossFamilyObservation(obs, {
|
|
855
|
+
model: key,
|
|
856
|
+
targetFamilies,
|
|
857
|
+
familiesOf: (m) => models.familiesOf(m),
|
|
858
|
+
sourceKinds,
|
|
859
|
+
cutoff,
|
|
860
|
+
}))
|
|
861
|
+
.map((obs) => obs.id);
|
|
862
|
+
if (noticeId && ms.notices) {
|
|
863
|
+
delete ms.notices[noticeId];
|
|
864
|
+
if (!Object.keys(ms.notices).length)
|
|
865
|
+
delete ms.notices;
|
|
866
|
+
}
|
|
867
|
+
delete ms.pendingReason;
|
|
868
|
+
delete ms.pendingEvidenceIds;
|
|
869
|
+
}
|
|
870
|
+
else if (ms.pendingReason === 'new_model') {
|
|
871
|
+
delete ms.pendingReason;
|
|
872
|
+
delete ms.pendingEvidenceIds;
|
|
873
|
+
}
|
|
874
|
+
ms.baselineRequested = true;
|
|
875
|
+
}
|
|
876
|
+
if (!familyTag?.pendingFamilies) {
|
|
877
|
+
delete ms.lastFamilyWokeAt;
|
|
878
|
+
delete ms.lastFamilyWokeStage;
|
|
879
|
+
}
|
|
880
|
+
store.saveWakeupState(wakeupState);
|
|
881
|
+
if (familyTag?.pendingFamilies)
|
|
882
|
+
scheduleWakeup();
|
|
883
|
+
}
|
|
884
|
+
emitChanged(key, kind);
|
|
885
|
+
return nextRecord;
|
|
886
|
+
},
|
|
887
|
+
text: (record) => {
|
|
888
|
+
const bits = [`已更新${record.kind === 'model' ? '模型' : '客户端'}画像 \`${record.key}\`(v${record.version})`];
|
|
889
|
+
if (record.kind === 'model') {
|
|
890
|
+
if (record.families?.length)
|
|
891
|
+
bits.push(`已生效系列:${record.families.join(' + ')}`);
|
|
892
|
+
if (record.pendingFamilies) {
|
|
893
|
+
const count = independentConfirmationCount(record.pendingFamilies.confirmers, hasVerifiedFamilyBootstrap(verifiedTagsByModel));
|
|
894
|
+
bits.push(`待确认系列:${record.pendingFamilies.families.join(' + ')}(${count}/2)`);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
return `${bits.join(';')}。`;
|
|
898
|
+
},
|
|
899
|
+
}));
|
|
900
|
+
ctx.effect(entry.op({
|
|
901
|
+
name: 'profiles.rebuild',
|
|
902
|
+
about: '从各可用观察来源的原始记录重建观察索引并重算实测统计。默认补回近 14 天的数据。',
|
|
903
|
+
input: object({
|
|
904
|
+
since: { description: '起始时间(毫秒时间戳或 ISO 日期,默认 14 天前)' },
|
|
905
|
+
}),
|
|
906
|
+
http: ['POST', '/api/plugins/model-profiles/rebuild'],
|
|
907
|
+
agent: true,
|
|
908
|
+
async run({ since }) {
|
|
909
|
+
const sinceMs = parseSince(since) ?? (Date.now() - WINDOW_MS);
|
|
910
|
+
return rebuild(sinceMs);
|
|
911
|
+
},
|
|
912
|
+
text: ({ count, sources: avail }) => `索引重建完成:共 ${count} 条观察记录(可用来源:${Object.entries(avail).filter(([, on]) => on).map(([k]) => k).join('、')})。`,
|
|
913
|
+
}));
|
|
914
|
+
},
|
|
915
|
+
};
|
|
916
|
+
}
|