@sleep2agi/commhub-server 0.9.0-preview.27 → 0.9.0-preview.270
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -3
- package/bin/commhub.ts +93 -9
- package/build-info.json +7 -0
- package/package.json +10 -8
- package/src/ack-create-request-transport.test.ts +182 -0
- package/src/ack-create-request.test.ts +52 -8
- package/src/admin-delete-network-http.test.ts +229 -0
- package/src/admin-networks-http.test.ts +88 -0
- package/src/adoption-candidates-http.test.ts +140 -0
- package/src/adoption-candidates.ts +158 -0
- package/src/agent-access-batch.test.ts +210 -0
- package/src/agent-access.ts +585 -0
- package/src/agent-acl-groups-http.test.ts +247 -0
- package/src/agent-acl-http.test.ts +691 -0
- package/src/agent-acl-slice3-http.test.ts +885 -0
- package/src/agent-department-grants.test.ts +129 -0
- package/src/agent-department-http.test.ts +215 -0
- package/src/agent-groups-perf.test.ts +223 -0
- package/src/agent-notice.ts +48 -0
- package/src/agent-team-whoami-http.test.ts +98 -0
- package/src/agent-teams-http.test.ts +330 -0
- package/src/agent-teams.ts +244 -0
- package/src/alias-baseline-2571.test.ts +162 -0
- package/src/alias-baseline.ts +113 -0
- package/src/alias-filter.test.ts +72 -0
- package/src/alias-filter.ts +42 -0
- package/src/api-host-supervisors-can-create-nodes.test.ts +350 -0
- package/src/api-host-supervisors-fallback.test.ts +6 -7
- package/src/api-host-supervisors-runtime-readiness.test.ts +195 -0
- package/src/api-nodes-shape.test.ts +131 -4
- package/src/auth-abuse-counters.test.ts +144 -0
- package/src/auth-abuse-counters.ts +122 -0
- package/src/auth-layer-shape.test.ts +105 -0
- package/src/auth-password-change-cli-tokens-http.test.ts +423 -0
- package/src/auth-sessions-http.test.ts +260 -0
- package/src/auth-validate.test.ts +5 -1
- package/src/auth-weak-password-login.test.ts +176 -0
- package/src/auth.ts +641 -68
- package/src/backfill-node-ids-2664.test.ts +128 -0
- package/src/binding-generation-http.test.ts +141 -0
- package/src/blocked-exit-on-reply.test.ts +122 -0
- package/src/broadcast-fanout-2721.test.ts +149 -0
- package/src/broadcast-fanout.ts +117 -0
- package/src/build-commit-report-http.test.ts +128 -0
- package/src/build-info.test.ts +60 -0
- package/src/build-info.ts +85 -0
- package/src/chain-attempt-dedup.test.ts +447 -0
- package/src/clip.test.ts +36 -0
- package/src/clip.ts +48 -0
- package/src/clone-node.test.ts +269 -0
- package/src/clone-node.ts +289 -0
- package/src/codex-config-flags.ts +77 -0
- package/src/codex-fork-contract.ts +23 -0
- package/src/codex-fork-migration.test.ts +38 -0
- package/src/commhub-bin-args.test.ts +85 -0
- package/src/config-apply-validate.test.ts +188 -1
- package/src/config-apply-validate.ts +222 -3
- package/src/cors-origins.test.ts +73 -0
- package/src/create-node-blocked-gate.test.ts +365 -0
- package/src/create-node-error-domain.test.ts +127 -0
- package/src/create-node-network-id.test.ts +91 -0
- package/src/create-node-tool-schema.test.ts +49 -0
- package/src/create-node-unicode-name.test.ts +126 -0
- package/src/create-node-validate.test.ts +199 -7
- package/src/create-node-validate.ts +232 -15
- package/src/create-node-workdir.test.ts +298 -0
- package/src/create-node.ts +88 -23
- package/src/daemon-provider-snapshots.test.ts +453 -0
- package/src/daemon-provider-snapshots.ts +327 -0
- package/src/daemon-token-owner-http.test.ts +346 -0
- package/src/dashboard-slash-routing-http.test.ts +109 -0
- package/src/db-adapter-guard.test.ts +148 -0
- package/src/db-adapter-translate.test.ts +128 -0
- package/src/db-adapter.ts +377 -91
- package/src/db-timestamp.test.ts +38 -0
- package/src/db-timestamp.ts +15 -0
- package/src/db.ts +1298 -153
- package/src/delivered-without-push.test.ts +140 -0
- package/src/department-groups-http.test.ts +209 -0
- package/src/department-groups-sync-http.test.ts +328 -0
- package/src/department-groups.ts +434 -0
- package/src/department-heads-http.test.ts +350 -0
- package/src/department-heads.ts +226 -0
- package/src/departments-agent-count.test.ts +139 -0
- package/src/departments-http.test.ts +185 -0
- package/src/departments-mcp-error-domain.test.ts +135 -0
- package/src/departments-mcp.test.ts +128 -0
- package/src/departments.ts +318 -0
- package/src/desktop-message-seam.test.ts +150 -0
- package/src/desktop-message.test.ts +368 -0
- package/src/dm-file-scope-http.test.ts +227 -0
- package/src/empty-node-sweeper.test.ts +104 -0
- package/src/empty-node-sweeper.ts +88 -0
- package/src/env-transport-gate-http.test.ts +240 -0
- package/src/env-transport-gate.ts +80 -0
- package/src/env-transport-policy.ts +56 -0
- package/src/etag-of.test.ts +57 -0
- package/src/event-loop-lag.test.ts +180 -0
- package/src/event-loop-lag.ts +201 -0
- package/src/expiry-counters.test.ts +187 -0
- package/src/expiry-counters.ts +227 -0
- package/src/expiry-evidence-db.test.ts +103 -0
- package/src/ext-token-shared.test.ts +60 -0
- package/src/ext-validation-regression.test.ts +10 -17
- package/src/external-schedule-edits-http.test.ts +321 -0
- package/src/external-schedule-edits-timestamps.test.ts +64 -0
- package/src/external-schedule-edits.ts +327 -0
- package/src/file-download-authz-dev-open.test.ts +1 -1
- package/src/file-download-authz.test.ts +25 -4
- package/src/file-download-date-bucket.test.ts +1 -1
- package/src/file-network-scope-dev-open.test.ts +1 -1
- package/src/file-network-scope.test.ts +7 -6
- package/src/group-membership-events-http.test.ts +264 -0
- package/src/group-messages-http.test.ts +483 -0
- package/src/group-messages.ts +297 -0
- package/src/health-anon-readers.ts +67 -0
- package/src/health-host-disk-2756.test.ts +71 -0
- package/src/health-identity-root.test.ts +98 -0
- package/src/health-redaction.test.ts +1599 -7
- package/src/health-status-reasons.test.ts +84 -0
- package/src/host-supervisor-identity-http.test.ts +152 -0
- package/src/host-supervisor-identity.ts +92 -0
- package/src/host-supervisors-daemon-version.test.ts +137 -0
- package/src/http-gzip.test.ts +94 -0
- package/src/http-gzip.ts +112 -0
- package/src/hub-catalog-read-http.test.ts +664 -0
- package/src/hub-provider-config.test.ts +166 -0
- package/src/hub-provider-config.ts +202 -0
- package/src/hub-timestamp.test.ts +38 -0
- package/src/hub-timestamp.ts +27 -0
- package/src/human-dm.ts +215 -0
- package/src/human-inbox.ts +42 -0
- package/src/inbox-caller.ts +49 -0
- package/src/inbox-count-sse.test.ts +318 -0
- package/src/inbox-count.ts +29 -0
- package/src/index.ts +6 -2
- package/src/license-state.test.ts +105 -0
- package/src/license-state.ts +48 -0
- package/src/lifecycle-error-domain.test.ts +149 -0
- package/src/list-ack-error-domain.test.ts +108 -0
- package/src/list-host-supervisors.test.ts +15 -4
- package/src/list-tasks-omit-default.test.ts +84 -0
- package/src/list-tasks-since-last.test.ts +100 -0
- package/src/list-tasks-since.test.ts +104 -0
- package/src/mcp-context-cost-http.test.ts +127 -0
- package/src/mcp-inflight.test.ts +92 -0
- package/src/mcp-inflight.ts +38 -0
- package/src/mcp-projects-events-http.test.ts +168 -0
- package/src/mcp-route-label-http.test.ts +120 -0
- package/src/mcp-write-network-resolution.test.ts +21 -0
- package/src/member-audit-network-id-http.test.ts +93 -0
- package/src/member-presence-http.test.ts +210 -0
- package/src/messages-ack-by-agent-http.test.ts +142 -0
- package/src/migrate-sqlite-to-pg.test.ts +47 -0
- package/src/migrate-sqlite-to-pg.ts +263 -0
- package/src/model-auth-notify-http.test.ts +181 -0
- package/src/model-auth-notify.ts +116 -0
- package/src/network-name-http.test.ts +75 -0
- package/src/network-quota-config.test.ts +100 -0
- package/src/network-rules-http.test.ts +169 -0
- package/src/network-rules.ts +129 -0
- package/src/network-scope.ts +222 -3
- package/src/network-token-membership-http.test.ts +186 -0
- package/src/node-alias-control.ts +12 -0
- package/src/node-attrs.test.ts +47 -2
- package/src/node-caller-identity-http.test.ts +1108 -0
- package/src/node-config-last-update.test.ts +126 -0
- package/src/node-config-last-update.ts +107 -0
- package/src/node-create-request-status-http.test.ts +105 -0
- package/src/node-daemon-bindings.test.ts +142 -0
- package/src/node-daemon-bindings.ts +135 -0
- package/src/node-failure-alert.test.ts +150 -0
- package/src/node-failure-alert.ts +177 -0
- package/src/node-files-transport.test.ts +350 -0
- package/src/node-health-codex-login.test.ts +120 -0
- package/src/node-health-dispatch-http.test.ts +373 -0
- package/src/node-health-guard-origin.test.ts +98 -0
- package/src/node-health-guard.ts +121 -0
- package/src/node-health-passthrough.test.ts +115 -0
- package/src/node-health-store.ts +101 -0
- package/src/node-id-alias.test.ts +190 -0
- package/src/node-identity-conflict-http.test.ts +269 -0
- package/src/node-identity-conflict.ts +142 -0
- package/src/node-identity-mismatch.test.ts +74 -0
- package/src/node-in-flight-tasks.ts +31 -0
- package/src/node-lifecycle-controllable.test.ts +64 -0
- package/src/node-lifecycle-controllable.ts +53 -0
- package/src/node-lifecycle-read-http.test.ts +257 -0
- package/src/node-lifecycle-read.ts +124 -0
- package/src/node-logs-transport.test.ts +266 -0
- package/src/node-peer-allowlist.test.ts +114 -0
- package/src/node-permissions-http.test.ts +901 -0
- package/src/node-permissions.ts +494 -0
- package/src/node-request-retention.test.ts +281 -0
- package/src/node-request-retention.ts +120 -0
- package/src/node-secret-rest-http.test.ts +190 -0
- package/src/node-secret-vault-inject.test.ts +132 -0
- package/src/node-security-write-gate.test.ts +72 -0
- package/src/node-serviceability.test.ts +86 -0
- package/src/node-serviceability.ts +124 -0
- package/src/node-session-control-http.test.ts +310 -0
- package/src/node-session-control.ts +258 -0
- package/src/node-skills-transport.test.ts +212 -0
- package/src/node-token-identity.ts +35 -0
- package/src/node-token-ownership.ts +51 -0
- package/src/node-token-privilege-http.test.ts +224 -0
- package/src/not-found-api-http.test.ts +67 -0
- package/src/observer-avatar-http.test.ts +103 -10
- package/src/observer-push.test.ts +76 -0
- package/src/opencode-catalog-report-http.test.ts +139 -0
- package/src/opencode-v2-catalog.test.ts +268 -0
- package/src/opencode-v2-catalog.ts +356 -0
- package/src/package-version-consistency.test.ts +25 -0
- package/src/parent-infer.test.ts +82 -0
- package/src/parent-infer.ts +110 -0
- package/src/parent-source-marker.test.ts +70 -0
- package/src/parent-source-orphan.test.ts +121 -0
- package/src/password-network-tokens.ts +25 -0
- package/src/peer-reply-atomic.test.ts +462 -0
- package/src/peer-reply-capability.test.ts +70 -0
- package/src/pg-worker.ts +87 -0
- package/src/poll-pacing.test.ts +74 -0
- package/src/poll-pacing.ts +123 -0
- package/src/probe-provider-error-domain.test.ts +145 -0
- package/src/project-dir-warn-clear-http.test.ts +132 -0
- package/src/project-viewer-can-http.test.ts +116 -0
- package/src/provider-skill-error-domain.test.ts +130 -0
- package/src/provider-tools-shape.test.ts +165 -0
- package/src/push.test.ts +20 -10
- package/src/push.ts +373 -9
- package/src/redact-tokens.test.ts +86 -0
- package/src/redact-tokens.ts +43 -0
- package/src/rejection-counters.test.ts +72 -0
- package/src/rejection-counters.ts +173 -0
- package/src/rename.ts +38 -10
- package/src/reply-target-derivation.test.ts +96 -0
- package/src/report-status-handover-capabilities-http.test.ts +124 -0
- package/src/report-status-host-schema.test.ts +235 -0
- package/src/report-status-resume-id-handover.test.ts +184 -0
- package/src/report-status-secret-keys.test.ts +140 -0
- package/src/require-explicit-test-db.ts +9 -0
- package/src/requirement-due-reminders-http.test.ts +620 -0
- package/src/requirement-due-reminders.ts +416 -0
- package/src/requirement-events-http.test.ts +318 -0
- package/src/requirement-events.test.ts +45 -0
- package/src/requirement-events.ts +144 -0
- package/src/requirement-notify.ts +165 -0
- package/src/requirement-participant-notify-http.test.ts +313 -0
- package/src/requirement-tag-ops-http.test.ts +454 -0
- package/src/requirement-tag-tree-http.test.ts +275 -0
- package/src/requirement-tag-tree.ts +127 -0
- package/src/requirement-tags.ts +102 -0
- package/src/requirements-abandoned-http.test.ts +236 -0
- package/src/requirements-assignee-drift.test.ts +154 -0
- package/src/requirements-comment-http.test.ts +174 -0
- package/src/requirements-completed-at-migration.test.ts +70 -0
- package/src/requirements-errors-mcp-http.test.ts +164 -0
- package/src/requirements-errors.ts +158 -0
- package/src/requirements-etag-http.test.ts +91 -0
- package/src/requirements-http.test.ts +709 -0
- package/src/requirements-last-event-http.test.ts +349 -0
- package/src/requirements-list-mcp-slim-http.test.ts +155 -0
- package/src/requirements-list-slim-http.test.ts +324 -0
- package/src/requirements-mcp.test.ts +180 -0
- package/src/requirements-migrate.ts +283 -0
- package/src/requirements-owner-strict-mcp-http.test.ts +145 -0
- package/src/requirements-people-http.test.ts +114 -0
- package/src/requirements-people-mcp-http.test.ts +231 -0
- package/src/requirements-people.ts +196 -0
- package/src/requirements-priority-lowest.test.ts +114 -0
- package/src/requirements-projects-network-echo.test.ts +57 -0
- package/src/requirements-projects-parent-http.test.ts +123 -0
- package/src/requirements-search-http.test.ts +182 -0
- package/src/requirements-search.test.ts +32 -0
- package/src/requirements-search.ts +145 -0
- package/src/requirements-seq-http.test.ts +193 -0
- package/src/requirements-seq-migration.test.ts +63 -0
- package/src/requirements-start-date.test.ts +125 -0
- package/src/requirements-stats-http.test.ts +357 -0
- package/src/requirements-stats.ts +195 -0
- package/src/requirements-status-participants-http.test.ts +222 -0
- package/src/requirements-upgrade-e2e.test.ts +126 -0
- package/src/requirements-upgrade-migration.test.ts +98 -0
- package/src/requirements.ts +2205 -0
- package/src/resolve-port.test.ts +57 -0
- package/src/resolve-port.ts +44 -0
- package/src/rest-alias-network-fallback-http.test.ts +123 -0
- package/src/rest-alias-network-fallback.test.ts +60 -0
- package/src/rest-alias-network-fallback.ts +65 -0
- package/src/rest-explicit-columns-http.test.ts +266 -0
- package/src/rest-identity.test.ts +130 -0
- package/src/rest-identity.ts +141 -0
- package/src/rest-projections.ts +72 -0
- package/src/rest-read-network-real-chain.test.ts +97 -0
- package/src/rest-write-network-resolution.test.ts +133 -0
- package/src/restart-readiness-http.test.ts +121 -0
- package/src/restricted-files.ts +76 -0
- package/src/retention-first-sweep-quiet.test.ts +31 -0
- package/src/retention.test.ts +100 -40
- package/src/retention.ts +423 -104
- package/src/route-callers-http.test.ts +120 -0
- package/src/route-timing.test.ts +218 -0
- package/src/route-timing.ts +262 -0
- package/src/rules-file-duplicate-alias.test.ts +234 -0
- package/src/rules-file-session-target.test.ts +207 -0
- package/src/rules-file-transport.test.ts +271 -0
- package/src/runtime-label.test.ts +22 -0
- package/src/runtime-label.ts +21 -0
- package/src/runtime-readiness.ts +90 -0
- package/src/schedule-agent-mcp-http.test.ts +486 -0
- package/src/schedule-agent.ts +252 -0
- package/src/schedule-starved.test.ts +92 -0
- package/src/schedule-starved.ts +114 -0
- package/src/scheduled-backoff-http.test.ts +203 -0
- package/src/scheduled-backoff.ts +64 -0
- package/src/scheduled-doorbell-nodeless-session.test.ts +134 -0
- package/src/scheduled-failure-backoff-2622.test.ts +145 -0
- package/src/scheduled-failure-code.test.ts +73 -0
- package/src/scheduled-failure-code.ts +105 -0
- package/src/scheduled-failures-http.test.ts +279 -0
- package/src/scheduled-failures.ts +425 -0
- package/src/scheduled-noprogress-backoff-2622.test.ts +163 -0
- package/src/scheduled-offline-backoff-probe.test.ts +56 -0
- package/src/scheduled-offline.test.ts +131 -0
- package/src/scheduled-offline.ts +66 -0
- package/src/scheduled-outcome-guidance-http.test.ts +139 -0
- package/src/scheduled-outcome-guidance.ts +9 -0
- package/src/scheduled-reply-unread-http.test.ts +212 -0
- package/src/scheduled-requirement-wake-http.test.ts +289 -0
- package/src/scheduled-requirement-wake.ts +125 -0
- package/src/scheduled-run-terminal.test.ts +290 -0
- package/src/scheduled-skip-blocking-task.test.ts +120 -0
- package/src/scheduled-skip-path-backoff-2622.test.ts +98 -0
- package/src/scheduled-stuck-http.test.ts +316 -0
- package/src/scheduled-stuck-notice-cap.test.ts +80 -0
- package/src/scheduled-stuck.ts +219 -0
- package/src/scheduled-tasks-http.test.ts +679 -0
- package/src/scheduled-tasks.ts +959 -0
- package/src/scheduled-work-outcome-http.test.ts +154 -0
- package/src/scheduled-work-outcome.ts +50 -0
- package/src/scoped-secrets.ts +167 -0
- package/src/secret-echo-negative-control.test.ts +118 -0
- package/src/send-dedup-request-id.test.ts +229 -0
- package/src/send-reply-agent-warning.test.ts +38 -38
- package/src/send-reply-alias-optional.test.ts +131 -0
- package/src/send-reply-attachments.test.ts +28 -7
- package/src/send_dedup.test.ts +54 -0
- package/src/send_dedup.ts +52 -6
- package/src/serve-error.test.ts +73 -0
- package/src/serve-error.ts +56 -0
- package/src/server.ts +4930 -377
- package/src/session-task-on-dispatch.ts +14 -0
- package/src/session-token-ownership-http.test.ts +122 -0
- package/src/shared/codex-inventory.ts +41 -0
- package/src/shared/daemon-provider-login.ts +31 -0
- package/src/shared/daemon-provider-snapshot.ts +52 -0
- package/src/shared/external-schedule-contract.ts +60 -0
- package/src/shared/node-name.test.ts +62 -0
- package/src/shared/node-name.ts +161 -0
- package/src/shared/probe-host-allowlist-drift.test.ts +45 -0
- package/src/shared/provider-application.ts +29 -0
- package/src/shared/provider-collection.ts +14 -0
- package/src/shared/provider-initialization.ts +8 -0
- package/src/shared/reserved-env-drift.test.ts +10 -0
- package/src/shared/scoped-secret-contract.ts +5 -0
- package/src/shared/task-content-limit-drift.test.ts +28 -0
- package/src/shared/task-content-limit.ts +25 -0
- package/src/side-thread-command-transport.test.ts +312 -0
- package/src/side-thread-command-transport.ts +318 -0
- package/src/side-thread-http-integration.test.ts +233 -0
- package/src/side-thread-http.ts +504 -0
- package/src/side-thread-production.test.ts +72 -0
- package/src/side-thread-production.ts +118 -0
- package/src/side-thread.test.ts +1067 -0
- package/src/side-thread.ts +2499 -0
- package/src/skillhub-http.test.ts +144 -0
- package/src/sqlite-close-checkpoint.test.ts +78 -0
- package/src/start-node.test.ts +265 -0
- package/src/start-request-error-domain.test.ts +182 -0
- package/src/start-skill-error-domain.test.ts +122 -0
- package/src/stats-versions-http.test.ts +65 -0
- package/src/status-alias-filter-http.test.ts +106 -0
- package/src/status-alias-resolver-http.test.ts +163 -0
- package/src/status-alias-resolver.ts +19 -0
- package/src/status-node-id-filter-http.test.ts +161 -0
- package/src/status-read-cache-http.test.ts +229 -0
- package/src/status-read-cache.ts +129 -0
- package/src/stop-delete-node.test.ts +567 -1
- package/src/task-access-http.test.ts +407 -0
- package/src/task-access.ts +420 -0
- package/src/task-activity.ts +60 -0
- package/src/task-auth-origin-http.test.ts +93 -0
- package/src/task-auth-origin.test.ts +24 -0
- package/src/task-auth-origin.ts +7 -0
- package/src/task-consumption.test.ts +508 -0
- package/src/task-diagnostic-http.test.ts +149 -0
- package/src/task-diagnostic.test.ts +115 -0
- package/src/task-diagnostic.ts +118 -0
- package/src/task-expiry-notice-http.test.ts +298 -0
- package/src/task-expiry-notice.ts +318 -0
- package/src/task-idempotency-mcp.test.ts +148 -0
- package/src/task-idempotency.test.ts +76 -0
- package/src/task-idempotency.ts +81 -0
- package/src/task-late-replies.ts +54 -0
- package/src/task-late-reply-http.test.ts +227 -0
- package/src/task-lifecycle-watcher-busy.test.ts +114 -0
- package/src/task-lifecycle-watcher.test.ts +209 -0
- package/src/task-lifecycle-watcher.ts +109 -0
- package/src/task-network-resolution-http.test.ts +140 -0
- package/src/task-not-found-error-domain.test.ts +114 -0
- package/src/task-offline-delivery-2668.test.ts +119 -0
- package/src/task-offline-delivery.ts +81 -0
- package/src/task-orphan-http.test.ts +287 -0
- package/src/task-orphan.ts +119 -0
- package/src/task-queue-ahead-http.test.ts +309 -0
- package/src/task-queue-ahead-scale.test.ts +236 -0
- package/src/task-queue-ahead.ts +186 -0
- package/src/task-rejection-log-http.test.ts +160 -0
- package/src/task-rejection-log.ts +61 -0
- package/src/task-sender-http.test.ts +143 -0
- package/src/task-stale-open-http.test.ts +292 -0
- package/src/task-stale-open.ts +103 -0
- package/src/tasks-pagination-http.test.ts +141 -0
- package/src/team-rules-status-http.test.ts +90 -0
- package/src/team-rules-status.test.ts +59 -0
- package/src/team-rules-status.ts +72 -0
- package/src/tmux-allowlist.test.ts +48 -0
- package/src/tool-audience-http.test.ts +248 -0
- package/src/tool-audience.ts +127 -0
- package/src/tools-list-json-schema.test.ts +94 -0
- package/src/tools.ts +4314 -392
- package/src/update-node-config-error-domain.test.ts +107 -0
- package/src/uploads-http.test.ts +6 -4
- package/src/uploads.ts +23 -4
- package/src/user-avatar-http.test.ts +74 -0
- package/src/user-avatar-image.ts +160 -0
- package/src/user-avatar-migration.test.ts +25 -0
- package/src/user-avatar-upload-http.test.ts +353 -0
- package/src/user-inbox-by-agent-http.test.ts +189 -0
- package/src/user-inbox-netid-notnull.test.ts +122 -0
- package/src/user-inbox-read-http.test.ts +223 -0
- package/src/user-inbox-schema.test.ts +54 -0
- package/src/version-stats.test.ts +66 -0
- package/src/version-stats.ts +109 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// #1459 ① P3 —— per-user 收件回读 + ack + 未读数 + redact-at-read。
|
|
2
|
+
//
|
|
3
|
+
// 承重的是**隔离**:A 只能读到 A 的。所以下面每条隔离断言都额外钉住探针身份 ——
|
|
4
|
+
// 首个注册用户会自动成为全局 admin,而 admin 在别处走的是不过滤的分支;
|
|
5
|
+
// 若探针恰好是 admin,隔离断言会"通过但什么都没证明"(#500/#506 同款)。
|
|
6
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
7
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
|
|
11
|
+
const PRIVATE_DB_DIR = mkdtempSync(join(tmpdir(), "anet-user-inbox-read-"));
|
|
12
|
+
process.env.COMMHUB_DB ||= join(PRIVATE_DB_DIR, "hub.db");
|
|
13
|
+
|
|
14
|
+
let server: ReturnType<typeof Bun.serve>;
|
|
15
|
+
let base = "";
|
|
16
|
+
let adminToken = "", aToken = "", bToken = "";
|
|
17
|
+
const MASTER_TOKEN = "legacy-master-token-for-test";
|
|
18
|
+
let aUserId = "", bUserId = "", aNet = "", bNet = "";
|
|
19
|
+
let adminUserId = "", adminNet = "";
|
|
20
|
+
|
|
21
|
+
const get = async (path: string, token: string) => {
|
|
22
|
+
const r = await fetch(`${base}${path}`, { headers: { Authorization: `Bearer ${token}` } });
|
|
23
|
+
return { status: r.status, body: await r.json() as any };
|
|
24
|
+
};
|
|
25
|
+
const post = async (path: string, token: string, body: unknown) => {
|
|
26
|
+
const r = await fetch(`${base}${path}`, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
29
|
+
body: JSON.stringify(body),
|
|
30
|
+
});
|
|
31
|
+
return { status: r.status, body: await r.json() as any };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function seedMessage(mid: string, userId: string, netId: string, content: string, meta?: string, acked = 0) {
|
|
35
|
+
const { db } = require("./db.js");
|
|
36
|
+
db.run(
|
|
37
|
+
`INSERT INTO user_inbox (message_id, network_id, user_id, from_session, kind, title, content, severity, meta_json, acked, acked_at)
|
|
38
|
+
VALUES (?1, ?2, ?3, 'node-x', 'agent_message', NULL, ?4, 'info', ?5, ?6, ?7)`,
|
|
39
|
+
[mid, netId, userId, content, meta ?? null, acked, acked ? "2026-01-01 00:00:00" : null],
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
beforeAll(async () => {
|
|
44
|
+
// 传统全局 master token:requireAuth 对 GET /api/* 放行,但 resolveRequestAuth
|
|
45
|
+
// 返回 null(没有 user)。这条路径是分支内 `if (!callerUserId)` 唯一能被触发的
|
|
46
|
+
// 场景 —— 必须在 import server.js 之前设,AUTH_TOKEN 是模块加载期读的常量。
|
|
47
|
+
process.env.COMMHUB_AUTH_TOKEN ||= MASTER_TOKEN;
|
|
48
|
+
|
|
49
|
+
const { db } = await import("./db.js");
|
|
50
|
+
const { register, addNetworkMember } = await import("./auth.js");
|
|
51
|
+
const stamp = Date.now();
|
|
52
|
+
|
|
53
|
+
// 首个注册用户 = 全局 admin。**故意先注册一个用不到的 admin**,这样下面
|
|
54
|
+
// 两个探针 A/B 都不是 admin —— 隔离断言才有分辨力。
|
|
55
|
+
const admin = register(`ui_admin_${stamp}`, "UiAdmin-Strong-1!");
|
|
56
|
+
expect(admin.ok).toBe(true);
|
|
57
|
+
adminToken = admin.token!;
|
|
58
|
+
adminUserId = db.get<{ user_id: string }>("SELECT user_id FROM users WHERE username = ?1", `ui_admin_${stamp}`)!.user_id;
|
|
59
|
+
adminNet = admin.network_id!;
|
|
60
|
+
|
|
61
|
+
const a = register(`ui_a_${stamp}`, "UiA-Strong-1!");
|
|
62
|
+
const b = register(`ui_b_${stamp}`, "UiB-Strong-1!");
|
|
63
|
+
expect(a.ok && b.ok).toBe(true);
|
|
64
|
+
aToken = a.token!; bToken = b.token!;
|
|
65
|
+
aNet = a.network_id!; bNet = b.network_id!;
|
|
66
|
+
aUserId = db.get<{ user_id: string }>("SELECT user_id FROM users WHERE username = ?1", `ui_a_${stamp}`)!.user_id;
|
|
67
|
+
bUserId = db.get<{ user_id: string }>("SELECT user_id FROM users WHERE username = ?1", `ui_b_${stamp}`)!.user_id;
|
|
68
|
+
|
|
69
|
+
// 前提断言:探针不是 admin。靠"注册顺序"是隐式前提,会随夹具变化悄悄失效,
|
|
70
|
+
// 所以显式断言。
|
|
71
|
+
// 承重的是 role ≠ "admin";这里钉死具体值(auth.ts:88 非首用户写 "user"),
|
|
72
|
+
// 因为 `not.toBe("admin")` 在 role 为 undefined(查不到行)时也会通过 —— 松判据
|
|
73
|
+
// 会朝"没问题"那边失败。
|
|
74
|
+
for (const [name, id] of [["A", aUserId], ["B", bUserId]] as const) {
|
|
75
|
+
const role = db.get<{ role: string }>("SELECT role FROM users WHERE user_id = ?1", id)?.role;
|
|
76
|
+
expect([name, role]).toEqual([name, "user"]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 🔴 B 必须在**同一个 network** 里也有一条私信。
|
|
80
|
+
// 第一版夹具让 A/B 各处一网,于是 addNetworkScope 顺手挡住了 B 的行 ——
|
|
81
|
+
// 变异掉 `WHERE user_id = ?1` 后隔离断言照样通过(M1/M2/M4 全部存活)。
|
|
82
|
+
// 同网同事之间,user_id 过滤是**唯一**的隔离手段,夹具必须落在那一格。
|
|
83
|
+
expect(addNetworkMember(aNet, bUserId, "member").ok).toBe(true);
|
|
84
|
+
|
|
85
|
+
seedMessage("dm_a1", aUserId, aNet, "A 的第一条");
|
|
86
|
+
seedMessage("dm_a2", aUserId, aNet, "A 的第二条");
|
|
87
|
+
seedMessage("dm_b_same_net", bUserId, aNet, "B 在 A 同网里的私信");
|
|
88
|
+
seedMessage("dm_b1", bUserId, bNet, "B 的私信");
|
|
89
|
+
// A 自己的、但落在 A 不是成员的 network 上的行(例如 A 被移出该网后的遗留)。
|
|
90
|
+
// 它是 addNetworkScope 这次调用的唯一 witnessed-red 对象:user_id 过滤对它无效。
|
|
91
|
+
seedMessage("dm_a_foreign_net", aUserId, bNet, "A 在外网的遗留私信");
|
|
92
|
+
// #1493 —— network_id 升到 schema 级 NOT NULL 后,「network_id 为 NULL 的行」已
|
|
93
|
+
// **schema 级不可能**(写路径原本三闸挡、现在 DB 直接拒)。原先手播的 dm_a_nonet /
|
|
94
|
+
// dm_admin_nonet 两条 NULL 夹具随之删除:
|
|
95
|
+
// · dm_a_nonet(证"受网络限制成员读不到 NULL 行")—— 网络 scope 隔离已由下面
|
|
96
|
+
// dm_a_foreign_net(A 自己的行、落在 A 非成员的网)覆盖,不丢覆盖。
|
|
97
|
+
// · dm_admin_nonet 重锚到 admin **自己网络**的非 NULL 行 dm_admin_own,保住
|
|
98
|
+
// "admin(scope 助手 no-op)仍只读自己的、不绕过 user_id 过滤"这条覆盖。
|
|
99
|
+
seedMessage("dm_admin_own", adminUserId, adminNet, "admin 自己网络里的私信");
|
|
100
|
+
// #1493 SDK马 建议:用**非 NULL** 行补回"admin(scope 助手 no-op)能读到别网的自己的行"
|
|
101
|
+
// 这维覆盖(原先靠 NULL 行,现 NULL 不可能)。对照 dm_a_foreign_net(受限成员读不到),
|
|
102
|
+
// 两边都不依赖 NULL。
|
|
103
|
+
seedMessage("dm_admin_foreign_net", adminUserId, bNet, "admin 在别网的自己的私信");
|
|
104
|
+
seedMessage("dm_a_read", aUserId, aNet, "A 已读的一条", undefined, 1);
|
|
105
|
+
seedMessage("dm_a_secret", aUserId, aNet,
|
|
106
|
+
"凭据在正文里 ntok_abcdef123456", JSON.stringify({ k: "ghp_" + "A".repeat(24) }));
|
|
107
|
+
|
|
108
|
+
const mod = await import("./server.js");
|
|
109
|
+
server = mod.bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
110
|
+
base = `http://127.0.0.1:${server.port}`;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
afterAll(() => {
|
|
114
|
+
try { server?.stop(true); } catch {}
|
|
115
|
+
try { rmSync(PRIVATE_DB_DIR, { recursive: true, force: true }); } catch {}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe("#1459 ① P3 GET /api/messages?scope=user", () => {
|
|
119
|
+
test("🔴 只返回调用者自己的消息 —— A 读不到 B 的", async () => {
|
|
120
|
+
const { status, body } = await get("/api/messages?scope=user", aToken);
|
|
121
|
+
expect(status).toBe(200);
|
|
122
|
+
expect(body.ok).toBe(true);
|
|
123
|
+
const ids = body.messages.map((m: any) => m.message_id);
|
|
124
|
+
expect(ids).toContain("dm_a1");
|
|
125
|
+
expect(ids).toContain("dm_a_read"); // 不加 unacked 时已读也要回来
|
|
126
|
+
expect(ids).not.toContain("dm_b_same_net"); // 承重:同网,只有 user_id 过滤挡得住
|
|
127
|
+
expect(ids).not.toContain("dm_b1"); // 跨网,scope 助手挡
|
|
128
|
+
expect(ids).not.toContain("dm_a_foreign_net"); // 承重:A 自己的行,只有 scope 助手挡得住
|
|
129
|
+
expect(body.messages.every((m: any) => m.user_id === aUserId)).toBe(true);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("🔴 收件人取自 auth ctx —— query 里指定别人的 user_id 无效", async () => {
|
|
133
|
+
const { body } = await get(`/api/messages?scope=user&user_id=${bUserId}`, aToken);
|
|
134
|
+
const ids = body.messages.map((m: any) => m.message_id);
|
|
135
|
+
expect(ids).not.toContain("dm_b_same_net");
|
|
136
|
+
expect(ids).not.toContain("dm_b1");
|
|
137
|
+
expect(body.messages.every((m: any) => m.user_id === aUserId)).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("🔴 redact-at-read:正文与 meta 里的凭据形状被遮住", async () => {
|
|
141
|
+
const { body } = await get("/api/messages?scope=user", aToken);
|
|
142
|
+
const row = body.messages.find((m: any) => m.message_id === "dm_a_secret");
|
|
143
|
+
expect(row).toBeTruthy();
|
|
144
|
+
expect(row.content).toContain("ntok_***redacted***");
|
|
145
|
+
expect(row.content).not.toContain("ntok_abcdef123456");
|
|
146
|
+
expect(row.meta_json).toContain("ghp_***redacted***");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// #1493 后 NULL 网络行不可能,原"受网络限制成员读不到 NULL 行"一测删除——
|
|
150
|
+
// 网络 scope 隔离已由上面 dm_a_foreign_net(承重断言,test 112 line 121)覆盖。
|
|
151
|
+
// admin 一测重锚到非 NULL:验 admin(scope 助手 no-op)**仍只读自己的、不绕过 user_id 过滤**。
|
|
152
|
+
test("admin(scope 助手 no-op)仍受 user_id 限制:只读自己的、不读别人的", async () => {
|
|
153
|
+
const { body } = await get("/api/messages?scope=user", adminToken);
|
|
154
|
+
const ids = body.messages.map((m: any) => m.message_id);
|
|
155
|
+
expect(ids).toContain("dm_admin_own"); // 读得到自己的
|
|
156
|
+
expect(ids).toContain("dm_admin_foreign_net"); // scope 助手 no-op → 跨网也读得到自己的
|
|
157
|
+
expect(ids).not.toContain("dm_a1"); // 承重:admin 不绕过 user_id 过滤读别人的
|
|
158
|
+
expect(body.messages.every((m: any) => m.user_id === adminUserId)).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("unread 是未读数而非总数(A:4 条里 3 条未读)", async () => {
|
|
162
|
+
const { body } = await get("/api/messages?scope=user", aToken);
|
|
163
|
+
expect(body.messages.length).toBe(4);
|
|
164
|
+
expect(body.unread).toBe(3);
|
|
165
|
+
expect(body.pending_count).toBe(body.unread);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("unacked=1 排掉已读那条", async () => {
|
|
169
|
+
const { body } = await get("/api/messages?scope=user&unacked=1", aToken);
|
|
170
|
+
const ids = body.messages.map((m: any) => m.message_id);
|
|
171
|
+
expect(ids).not.toContain("dm_a_read"); // 承重:集合里确实有已读行才有分辨力
|
|
172
|
+
expect(ids.sort()).toEqual(["dm_a1", "dm_a2", "dm_a_secret"]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("未鉴权 ⇒ 401(/api 全局闸)", async () => {
|
|
176
|
+
const r = await fetch(`${base}/api/messages?scope=user`);
|
|
177
|
+
expect(r.status).toBe(401);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("🔴 legacy master token 过得了全局闸但没有 user ⇒ 401,不能回一个空列表", async () => {
|
|
181
|
+
// 这条才是分支内 `if (!callerUserId)` 的 witnessed-red:把它换成
|
|
182
|
+
// `?? ""` 后本条从 401 变成 200 + 空列表 —— "看起来正常"的错误答案。
|
|
183
|
+
const { status, body } = await get("/api/messages?scope=user", MASTER_TOKEN);
|
|
184
|
+
expect([status, body.error]).toEqual([401, "auth_required"]);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("alias 分支未受影响(dashboard 依赖它)", async () => {
|
|
188
|
+
const { status, body } = await get("/api/messages", adminToken);
|
|
189
|
+
expect(status).toBe(200);
|
|
190
|
+
expect(body.ok).toBe(true);
|
|
191
|
+
expect(Array.isArray(body.messages)).toBe(true);
|
|
192
|
+
expect(body.unread).toBeUndefined(); // 老分支不该多出新字段
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe("#1459 ① P3 POST /api/messages/ack", () => {
|
|
197
|
+
test("ack 自己的消息 ⇒ acked 置位、未读数下降", async () => {
|
|
198
|
+
const before = (await get("/api/messages?scope=user", aToken)).body.unread;
|
|
199
|
+
const { status, body } = await post("/api/messages/ack", aToken, { message_id: "dm_a1" });
|
|
200
|
+
expect(status).toBe(200);
|
|
201
|
+
expect(body.acked).toBe(1);
|
|
202
|
+
const after = (await get("/api/messages?scope=user", aToken)).body.unread;
|
|
203
|
+
expect(after).toBe(before - 1);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("🔴 ack 不了同网同事的消息 —— 改动行数为 0,且对方仍是未读", async () => {
|
|
207
|
+
const { body } = await post("/api/messages/ack", aToken, { message_id: "dm_b_same_net" });
|
|
208
|
+
expect(body.acked).toBe(0);
|
|
209
|
+
const bView = (await get("/api/messages?scope=user", bToken)).body;
|
|
210
|
+
expect(bView.messages.find((m: any) => m.message_id === "dm_b_same_net").acked).toBe(0);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("ack 跨网的消息同样为 0", async () => {
|
|
214
|
+
const { body } = await post("/api/messages/ack", aToken, { message_id: "dm_b1" });
|
|
215
|
+
expect(body.acked).toBe(0);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("缺参 ⇒ 400;未鉴权 ⇒ 401", async () => {
|
|
219
|
+
expect((await post("/api/messages/ack", aToken, {})).status).toBe(400);
|
|
220
|
+
const r = await fetch(`${base}/api/messages/ack`, { method: "POST", body: "{}" });
|
|
221
|
+
expect(r.status).toBe(401);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// #1459 ① — user_inbox 建表 + 幂等打底(P1)。零行为变化,只落 schema。
|
|
2
|
+
//
|
|
3
|
+
// 承重属性(SDK马 review 要点):message_id 即主键 → send_desktop_message 因 HTTP
|
|
4
|
+
// 响应丢失被重试时,同一 dm_<uuid> 用 INSERT OR IGNORE 不会插出重复行(前端免去重)。
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from "bun:test";
|
|
7
|
+
import { db } from "./db.js";
|
|
8
|
+
|
|
9
|
+
describe("#1459 user_inbox schema (P1)", () => {
|
|
10
|
+
test("table exists with the expected columns", () => {
|
|
11
|
+
const cols = db.all<{ name: string }>("PRAGMA table_info(user_inbox)").map(c => c.name);
|
|
12
|
+
for (const c of ["message_id", "network_id", "user_id", "from_session", "kind", "title", "content", "severity", "meta_json", "acked", "created_at", "acked_at"]) {
|
|
13
|
+
expect(cols).toContain(c);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// 注:这条钉的是「主键在我们以为的那一列」(SQLite 行为),**不是**「写入路径幂等」——
|
|
18
|
+
// 后者要 P2 驱动真实 send_desktop_message 两次来证(SDK马 review)。这里只保证主键选对。
|
|
19
|
+
test("message_id is PRIMARY KEY → INSERT OR IGNORE dedups on the same id", () => {
|
|
20
|
+
const mid = `dm_test_${Date.now()}`;
|
|
21
|
+
try {
|
|
22
|
+
const ins = () => db.run(
|
|
23
|
+
`INSERT OR IGNORE INTO user_inbox (message_id, network_id, user_id, from_session, content)
|
|
24
|
+
VALUES (?1, ?2, ?3, ?4, ?5)`,
|
|
25
|
+
[mid, "net_test_1459", "u_test_1459", "sender-a", "hello"],
|
|
26
|
+
);
|
|
27
|
+
ins();
|
|
28
|
+
ins(); // 同 message_id 第二次插入应被 IGNORE
|
|
29
|
+
const n = db.get<{ n: number }>("SELECT COUNT(*) AS n FROM user_inbox WHERE message_id = ?1", mid)?.n ?? 0;
|
|
30
|
+
expect(n).toBe(1);
|
|
31
|
+
} finally {
|
|
32
|
+
db.run("DELETE FROM user_inbox WHERE message_id = ?1", mid);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("defaults: acked=0, kind/severity='info'", () => {
|
|
37
|
+
const mid = `dm_def_${Date.now()}`;
|
|
38
|
+
try {
|
|
39
|
+
db.run(
|
|
40
|
+
// #1493 后 network_id 是 NOT NULL,补上(本测试只验其它列的默认值)
|
|
41
|
+
`INSERT INTO user_inbox (message_id, network_id, user_id, content) VALUES (?1, ?2, ?3, ?4)`,
|
|
42
|
+
[mid, "net_def_1459", "u_def_1459", "body"],
|
|
43
|
+
);
|
|
44
|
+
const row = db.get<{ acked: number; kind: string; severity: string }>(
|
|
45
|
+
"SELECT acked, kind, severity FROM user_inbox WHERE message_id = ?1", mid,
|
|
46
|
+
);
|
|
47
|
+
expect(row?.acked).toBe(0);
|
|
48
|
+
expect(row?.kind).toBe("info");
|
|
49
|
+
expect(row?.severity).toBe("info");
|
|
50
|
+
} finally {
|
|
51
|
+
db.run("DELETE FROM user_inbox WHERE message_id = ?1", mid);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// #2720 —— 版本债务聚合:无版本要按 agent 拆,别把「没有版本概念」算成债务。
|
|
2
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
3
|
+
import { db } from "./db.js";
|
|
4
|
+
import { versionStats } from "./version-stats.js";
|
|
5
|
+
|
|
6
|
+
let networkId = "";
|
|
7
|
+
|
|
8
|
+
function insertSession(alias: string, agent: string, version: string | null, status: string) {
|
|
9
|
+
db.run(
|
|
10
|
+
`INSERT INTO sessions (resume_id, alias, agent, version, status, network_id, registered_at)
|
|
11
|
+
VALUES (?1, ?2, ?3, ?4, ?5, ?6, '2026-10-01 00:00:00')`,
|
|
12
|
+
[`res_${alias}`, alias, agent, version, status, networkId],
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
beforeAll(async () => {
|
|
17
|
+
const { register } = await import("./auth.js");
|
|
18
|
+
const auth = register(`verstats_${Date.now()}`, "VerStats-Str0ng-1!", undefined, "watcher");
|
|
19
|
+
expect(auth.ok).toBe(true);
|
|
20
|
+
networkId = auth.network_id!;
|
|
21
|
+
|
|
22
|
+
insertSession("n-new", "agent-node:opencode", "2.3.0-preview.199", "idle");
|
|
23
|
+
insertSession("n-old", "agent-node:opencode", "2.3.0-preview.150", "idle");
|
|
24
|
+
insertSession("n-old-2", "agent-node:opencode", "2.3.0-preview.150", "working");
|
|
25
|
+
insertSession("n-gone", "agent-node:opencode", "2.3.0-preview.150", "offline");
|
|
26
|
+
// LLM 自己调工具的会话:没有版本是 n/a,不是债务
|
|
27
|
+
insertSession("cc-1", "claude-code", null, "idle");
|
|
28
|
+
insertSession("cc-2", "claude-code", null, "offline");
|
|
29
|
+
// 老 agent-node:该报没报,是真债务
|
|
30
|
+
insertSession("old-node-1", "agent-node:claude", null, "idle");
|
|
31
|
+
}, 30_000);
|
|
32
|
+
|
|
33
|
+
afterAll(() => {});
|
|
34
|
+
|
|
35
|
+
describe("versionStats (#2720)", () => {
|
|
36
|
+
test("counts sessions and active sessions for the network", () => {
|
|
37
|
+
const s = versionStats(networkId);
|
|
38
|
+
expect(s.sessions).toBeGreaterThanOrEqual(7);
|
|
39
|
+
expect(s.active).toBeGreaterThanOrEqual(5);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("keeps 'no version' split by agent, with version_expected flag", () => {
|
|
43
|
+
const s = versionStats(networkId);
|
|
44
|
+
const cc = s.no_version_by_agent.find((x) => x.agent === "claude-code");
|
|
45
|
+
const oldNode = s.no_version_by_agent.find((x) => x.agent === "agent-node:claude");
|
|
46
|
+
expect(cc?.version_expected).toBe(false); // LLM 工具调用:n/a
|
|
47
|
+
expect(oldNode?.version_expected).toBe(true); // 老节点:真债务
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("active_missing_version excludes producers with no version concept", () => {
|
|
51
|
+
const s = versionStats(networkId);
|
|
52
|
+
// 只有 old-node-1 计入(cc-1 是 n/a)
|
|
53
|
+
expect(s.active_missing_version).toBe(1);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("active_behind_same_agent counts actives on a non-top version", () => {
|
|
57
|
+
const s = versionStats(networkId);
|
|
58
|
+
// .150 有 2 个在线(idle+working),.199 是最高的一个
|
|
59
|
+
expect(s.active_behind_same_agent).toBeGreaterThanOrEqual(2);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("scoping by an unknown network yields nothing", () => {
|
|
63
|
+
const s = versionStats("net_does_not_exist");
|
|
64
|
+
expect(s.sessions).toBe(0);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// #2720 —— 让「版本债务」自己更新,不靠人跑 SQL。
|
|
2
|
+
//
|
|
3
|
+
// 背景(2026-10-27 生产只读统计):370 个 session 里 159 个没有版本号,
|
|
4
|
+
// 其中 33 个**还在线**。继续拆下去才看清真相:
|
|
5
|
+
// · 24 个的 `agent` 是 `claude-code` —— 那是 Claude 会话自己调
|
|
6
|
+
// `commhub_report_status(status=…, task=…)` 写的,**它没有 version 这个概念**;
|
|
7
|
+
// · 剩下 9 个才是老 agent-node(#1809 之前每次上报不带 version)。
|
|
8
|
+
// ⇒ 「无版本」不是一个桶:对 `claude-code` 是 n/a,对 agent-node 才是债务。
|
|
9
|
+
// 把两者混在一起算,会得出「升级节点能修好 33 个」的错误结论(只能修好 9 个)。
|
|
10
|
+
//
|
|
11
|
+
// 这个模块只做聚合(只读),返回:
|
|
12
|
+
// by_version —— (agent, version) → 总数/在线数
|
|
13
|
+
// no_version —— 按 agent 拆开的「无版本」,让调用方自己判 n/a 还是债务
|
|
14
|
+
// agent_kind —— 该 agent 的上报方式(`llm-tool-call` = 不自带版本)
|
|
15
|
+
|
|
16
|
+
import { db } from "./db.js";
|
|
17
|
+
|
|
18
|
+
/** 这些 agent 的上报者是 LLM 会话自己调工具,没有打包版本号可报(不是缺字段)。 */
|
|
19
|
+
const LLM_TOOL_CALL_AGENTS = new Set(["claude-code"]);
|
|
20
|
+
|
|
21
|
+
export type VersionBucket = {
|
|
22
|
+
agent: string;
|
|
23
|
+
version: string | null;
|
|
24
|
+
sessions: number;
|
|
25
|
+
active: number;
|
|
26
|
+
/** false = 这个 agent 没有版本概念(n/a),而不是“该报未报”。 */
|
|
27
|
+
version_expected: boolean;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type VersionStats = {
|
|
31
|
+
network_id: string | null;
|
|
32
|
+
sessions: number;
|
|
33
|
+
active: number;
|
|
34
|
+
by_version: VersionBucket[];
|
|
35
|
+
no_version_by_agent: Array<{ agent: string; sessions: number; version_expected: boolean }>;
|
|
36
|
+
/** 在线且「该报版本却没报」的总数 —— 这才是真正的债务口径。 */
|
|
37
|
+
active_missing_version: number;
|
|
38
|
+
/** 在线且版本落后于「在线里最高版本」的数量(只对字符串完全可比的同 agent 生效)。 */
|
|
39
|
+
active_behind_same_agent: number;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export function versionStats(networkId: string | null = null): VersionStats {
|
|
43
|
+
const rows = db.all<{ agent: string | null; version: string | null; status: string | null; c: number }>(
|
|
44
|
+
`SELECT COALESCE(agent, '') AS agent,
|
|
45
|
+
COALESCE(NULLIF(version, ''), '') AS version,
|
|
46
|
+
COALESCE(status, '') AS status,
|
|
47
|
+
COUNT(*) AS c
|
|
48
|
+
FROM sessions
|
|
49
|
+
WHERE (?1 IS NULL OR network_id = ?1)
|
|
50
|
+
GROUP BY 1, 2, 3`,
|
|
51
|
+
networkId,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const buckets = new Map<string, VersionBucket>();
|
|
55
|
+
let sessions = 0;
|
|
56
|
+
let active = 0;
|
|
57
|
+
for (const r of rows) {
|
|
58
|
+
const isActive = r.status !== "offline";
|
|
59
|
+
sessions += r.c;
|
|
60
|
+
if (isActive) active += r.c;
|
|
61
|
+
const version = r.version === "" ? null : r.version;
|
|
62
|
+
const key = `${r.agent}\u0000${version ?? ""}`;
|
|
63
|
+
const cur = buckets.get(key) ?? {
|
|
64
|
+
agent: r.agent,
|
|
65
|
+
version,
|
|
66
|
+
sessions: 0,
|
|
67
|
+
active: 0,
|
|
68
|
+
version_expected: !LLM_TOOL_CALL_AGENTS.has(r.agent),
|
|
69
|
+
};
|
|
70
|
+
cur.sessions += r.c;
|
|
71
|
+
if (isActive) cur.active += r.c;
|
|
72
|
+
buckets.set(key, cur);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const all = [...buckets.values()].sort((a, b) => b.sessions - a.sessions || a.agent.localeCompare(b.agent));
|
|
76
|
+
|
|
77
|
+
const noVersion = all
|
|
78
|
+
.filter((b) => b.version === null)
|
|
79
|
+
.map((b) => ({ agent: b.agent, sessions: b.sessions, version_expected: b.version_expected }));
|
|
80
|
+
|
|
81
|
+
// 每个 agent 在「在线」行里出现过的最高版本(仅用于粗判落后;不做语义版本比较,
|
|
82
|
+
// 只在字符串完全一致时才算“同一个版本”)。
|
|
83
|
+
const highest = new Map<string, string>();
|
|
84
|
+
for (const b of all) {
|
|
85
|
+
if (!b.version || b.active === 0) continue;
|
|
86
|
+
const cur = highest.get(b.agent);
|
|
87
|
+
if (!cur || b.version.localeCompare(cur) > 0) highest.set(b.agent, b.version);
|
|
88
|
+
}
|
|
89
|
+
let behind = 0;
|
|
90
|
+
for (const b of all) {
|
|
91
|
+
if (!b.version || b.active === 0) continue;
|
|
92
|
+
const top = highest.get(b.agent);
|
|
93
|
+
if (top && b.version !== top) behind += b.active;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const activeMissingVersion = all
|
|
97
|
+
.filter((b) => b.version === null && b.version_expected)
|
|
98
|
+
.reduce((n, b) => n + b.active, 0);
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
network_id: networkId,
|
|
102
|
+
sessions,
|
|
103
|
+
active,
|
|
104
|
+
by_version: all,
|
|
105
|
+
no_version_by_agent: noVersion,
|
|
106
|
+
active_missing_version: activeMissingVersion,
|
|
107
|
+
active_behind_same_agent: behind,
|
|
108
|
+
};
|
|
109
|
+
}
|