@sleep2agi/commhub-server 0.9.0-preview.28 → 0.9.0-preview.280
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 +215 -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 +888 -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 +228 -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/all-status-cache.test.ts +31 -0
- package/src/all-status-cache.ts +37 -0
- package/src/anet-variant-real-daemon-http.test.ts +184 -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 +218 -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-sec1.test.ts +37 -0
- package/src/config-apply-validate.test.ts +188 -1
- package/src/config-apply-validate.ts +226 -3
- package/src/contracts/session-project-create.ts +14 -0
- package/src/contracts/session-source-delivery.ts +16 -0
- package/src/contracts/session-source-directory.ts +54 -0
- package/src/contracts/session-source-evidence.ts +72 -0
- package/src/contracts/session-source-execution.ts +24 -0
- package/src/contracts/session-source-transport.ts +18 -0
- 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 +59 -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 +1334 -154
- 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 +126 -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 +496 -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 +398 -0
- package/src/node-session-control.ts +316 -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/node-token-usage.test.ts +128 -0
- package/src/node-token-usage.ts +228 -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 +282 -0
- package/src/opencode-v2-catalog.ts +357 -0
- package/src/package-self-contained.test.ts +32 -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 +272 -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 +280 -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 +964 -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 +5033 -377
- package/src/session-fork-store.test.ts +43 -0
- package/src/session-fork-store.ts +51 -0
- package/src/session-project-attach-migration.test.ts +22 -0
- package/src/session-project-attach-native.test.ts +121 -0
- package/src/session-project-create-http.test.ts +407 -0
- package/src/session-project-create-native.test.ts +290 -0
- package/src/session-project-create.ts +159 -0
- package/src/session-source-admission-store.ts +58 -0
- package/src/session-source-create.test.ts +155 -0
- package/src/session-source-create.ts +97 -0
- package/src/session-source-delivery.ts +109 -0
- package/src/session-source-directory-http.test.ts +192 -0
- package/src/session-source-evidence.test.ts +898 -0
- package/src/session-source-evidence.ts +191 -0
- package/src/session-source-execution.ts +87 -0
- package/src/session-source-grant.test.ts +117 -0
- package/src/session-source-grant.ts +78 -0
- package/src/session-source-issuer.test.ts +250 -0
- package/src/session-source-issuer.ts +164 -0
- package/src/session-source-transport.ts +375 -0
- 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-node-secrets-capable-http.test.ts +44 -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 +512 -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 +117 -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/token-usage-http.test.ts +156 -0
- package/src/tool-audience-http.test.ts +266 -0
- package/src/tool-audience.ts +130 -0
- package/src/tools-list-json-schema.test.ts +94 -0
- package/src/tools.ts +4530 -471
- 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,84 @@
|
|
|
1
|
+
// `status_reasons` 的**值域**必须与它的**生产者**逐个对应(外部复核的判据)。
|
|
2
|
+
//
|
|
3
|
+
// ## 为什么这一格值得一条断言
|
|
4
|
+
//
|
|
5
|
+
// `/health.status` 只有两个取值(ok / degraded),而 `status_reasons` 是回答
|
|
6
|
+
// 「ok 到底是**真的没问题**,还是**检查没跑**」的唯一读数。它的值域偏离生产者时:
|
|
7
|
+
//
|
|
8
|
+
// 值域比生产者少 ⇒ 两个成因合并成一个字 ⇒ 读的人分不出该修哪(合并)
|
|
9
|
+
// 值域比生产者多 ⇒ 有原因却没有任何代码会产生它 ⇒ 读者为它设计一条不存在的修法(死值)
|
|
10
|
+
//
|
|
11
|
+
// 两种都不红:`status` 照样是 ok/degraded,`status_reasons` 照样是数组。
|
|
12
|
+
//
|
|
13
|
+
// ## 为什么这一份是**声明**而不是引用
|
|
14
|
+
//
|
|
15
|
+
// push 点保留字面量(`statusReasons.push("db_unreadable")`),`STATUS_REASONS` 只做靶子。
|
|
16
|
+
// 改成 `push(STATUS_REASONS[0])` 之后,抽取只能看见下标、看不见成因,
|
|
17
|
+
// 而「哪一行推了什么」正是这条检查要看的东西。
|
|
18
|
+
//
|
|
19
|
+
// ## 断言
|
|
20
|
+
//
|
|
21
|
+
// ① 源码里所有 `statusReasons.push("X")` 的字面量集合 == STATUS_REASONS
|
|
22
|
+
// ② push 点数 == 不同字面量数(同一个成因不许有两处 push —— 那会让「一个成因」看起来像两个)
|
|
23
|
+
// ③ 每个 STATUS_REASONS 的成员都真的在某处被 push(无死值)
|
|
24
|
+
import { describe, expect, test } from "bun:test";
|
|
25
|
+
import { readFileSync } from "node:fs";
|
|
26
|
+
|
|
27
|
+
const src = readFileSync(new URL("./server.ts", import.meta.url), "utf8");
|
|
28
|
+
|
|
29
|
+
/** 源码里所有 `statusReasons.push("literal")` 的字面量(保序、允许重复)。 */
|
|
30
|
+
export function pushedReasonLiterals(source: string): string[] {
|
|
31
|
+
return [...source.matchAll(/statusReasons\s*\.\s*push\(\s*"([a-z0-9_]+)"\s*\)/g)].map((m) => m[1]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe("#status_reasons 值域 == 生产者集合", () => {
|
|
35
|
+
test("① push 的字面量集合与 STATUS_REASONS 相等", async () => {
|
|
36
|
+
const { STATUS_REASONS } = await import("./server.js");
|
|
37
|
+
const pushed = new Set(pushedReasonLiterals(src));
|
|
38
|
+
expect([...pushed].sort()).toEqual([...STATUS_REASONS].sort());
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// ② 报成**向量**而不是一个数:`1,1` 与 `1,2` 在「点数 == 不同值数」这条上都会红,
|
|
42
|
+
// 但前者是「新增了一类成因」,后者是「同一个成因被推了两次」—— 处置相反。
|
|
43
|
+
// 单条计数断言把这两种压成一格,而它读起来更严格。
|
|
44
|
+
test("② 每个成因恰好一个生产者(报向量,不是一个数)", () => {
|
|
45
|
+
const all = pushedReasonLiterals(src);
|
|
46
|
+
const counts: Record<string, number> = {};
|
|
47
|
+
for (const r of all) counts[r] = (counts[r] ?? 0) + 1;
|
|
48
|
+
const vector = Object.entries(counts).sort().map(([k, v]) => `${k}=${v}`).join(" · ");
|
|
49
|
+
expect(vector).toBe(
|
|
50
|
+
"db_unreadable=1 · license_unreadable=1",
|
|
51
|
+
);
|
|
52
|
+
// 上面那条是**精确向量**:新增一类或某类多一处,都会让它红,
|
|
53
|
+
// 而且失败信息里直接看得出是哪种(多了一个 `x=1` 还是某个变成 `=2`)。
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// ⑤ 域不能是空集,也不能是全集 —— 否则上面几条会在空集上恒真。
|
|
57
|
+
// 这正是「取反后仍然绿」的那一格:把 STATUS_REASONS 清空,①(集合相等)与 ③(无死值)
|
|
58
|
+
// 都会通过,因为没有东西可比;而它们看起来仍然在守东西。
|
|
59
|
+
test("⑤ 值域非空且不是全集(至少两类可区分)", async () => {
|
|
60
|
+
const { STATUS_REASONS } = await import("./server.js");
|
|
61
|
+
const pushed = new Set(pushedReasonLiterals(src));
|
|
62
|
+
// 下界:这个字段存在的理由就是区分「真的没问题」与「检查没跑」——至少要两类。
|
|
63
|
+
expect(STATUS_REASONS.length).toBeGreaterThanOrEqual(2);
|
|
64
|
+
// 上界:值域的成员必须都在源码里出现(否则是死值,由 ③ 报)——
|
|
65
|
+
// 这里再钉一条「域不比生产者宽」,因为「全集」正是那种能让谓词恒真的情形。
|
|
66
|
+
expect(STATUS_REASONS.length).toBeLessThanOrEqual(pushed.size + 0 * 0 + 0);
|
|
67
|
+
expect(pushed.size).toBeGreaterThan(0);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("③ 没有死值:STATUS_REASONS 每个成员都在源码里被 push 过", async () => {
|
|
71
|
+
const { STATUS_REASONS } = await import("./server.js");
|
|
72
|
+
const pushed = new Set(pushedReasonLiterals(src));
|
|
73
|
+
for (const r of STATUS_REASONS) expect(pushed.has(r)).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("④ status 由 reasons 派生,不是独立写的第二个真相", async () => {
|
|
77
|
+
const { statusFromReasons } = await import("./server.js");
|
|
78
|
+
// 空 ⇒ ok;任一 ⇒ degraded。这条同时钉住「ok 不代表检查跑过」——
|
|
79
|
+
// 它只代表「没有成因被推上来」。
|
|
80
|
+
expect(statusFromReasons([])).toBe("ok");
|
|
81
|
+
expect(statusFromReasons(["db_unreadable"])).toBe("degraded");
|
|
82
|
+
expect(statusFromReasons(["db_unreadable", "license_unreadable"])).toBe("degraded");
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { afterAll, beforeAll, beforeEach, expect, test } from "bun:test";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { db } from "./db.js";
|
|
4
|
+
import { register } from "./auth.js";
|
|
5
|
+
import { registerTools } from "./tools.js";
|
|
6
|
+
import { hostSupervisorIdentityRows } from "./host-supervisor-identity.js";
|
|
7
|
+
|
|
8
|
+
if (!process.env.COMMHUB_DB && !process.env.COMMHUB_TEST_PG_URL) throw Error("explicit fixture DB required");
|
|
9
|
+
let net: string, foreign: string, user: string, token: string, hub: any, base: string;
|
|
10
|
+
let sequence = 0;
|
|
11
|
+
const next = () => `n_lhs1109_${++sequence}`;
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
const auth = register(`lhs1109_${Date.now()}`, "FixturePassword1109!", undefined, "fixture");
|
|
14
|
+
if (!auth.ok || !auth.token || !auth.user || !auth.network_id) throw Error("fixture registration failed");
|
|
15
|
+
user = auth.user.user_id; token = auth.token; net = auth.network_id;
|
|
16
|
+
foreign = `net_foreign_lhs1109_${Date.now()}`;
|
|
17
|
+
db.run("INSERT INTO networks(network_id,network_name,owner_id) VALUES(?1,'foreign',?2)", [foreign, user]);
|
|
18
|
+
process.env.HOST = "127.0.0.1";
|
|
19
|
+
const { bootServer } = await import("./server.js");
|
|
20
|
+
hub = await bootServer({ port: 0 }); base = `http://127.0.0.1:${hub.port}`;
|
|
21
|
+
}, 30_000);
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
db.run("DELETE FROM api_tokens WHERE name LIKE 'node:lhs1109_%'");
|
|
24
|
+
db.run("DELETE FROM sessions WHERE alias LIKE 'lhs1109_%'");
|
|
25
|
+
db.run("DELETE FROM nodes WHERE alias LIKE 'lhs1109_%'");
|
|
26
|
+
});
|
|
27
|
+
afterAll(() => hub?.stop(true));
|
|
28
|
+
|
|
29
|
+
function node(alias: string, network = net, owner: string | null = user) {
|
|
30
|
+
const id = next();
|
|
31
|
+
db.run(`INSERT INTO nodes(node_id,node_name,alias,network_id,owner_user_id,config_snapshot)
|
|
32
|
+
VALUES(?1,?2,?2,?3,?4,'{"role":"host_supervisor"}')`, [id, `lhs1109_${alias}`, network, owner]);
|
|
33
|
+
return id;
|
|
34
|
+
}
|
|
35
|
+
function credential(id: string, opts: { bound?: string | null; name?: string; issuer?: string; epoch?: number; network?: string; scope?: string; expired?: boolean; revoked?: boolean } = {}) {
|
|
36
|
+
const n = db.get<any>("SELECT alias, network_id FROM nodes WHERE node_id=?1", id)!;
|
|
37
|
+
const tid = `tok_lhs1109_${++sequence}`;
|
|
38
|
+
db.run(`INSERT INTO api_tokens(token_id,token_hash,user_id,network_id,scope,name,bound_node_id,node_identity_epoch,expires_at,revoked_at)
|
|
39
|
+
VALUES(?1,?2,?3,?4,?5,?6,?7,?8,?9,?10)`, [tid, `hash_${tid}`, opts.issuer ?? user,
|
|
40
|
+
opts.network ?? n.network_id, opts.scope ?? "network", `node:${opts.name ?? n.alias}`,
|
|
41
|
+
opts.bound === undefined ? id : opts.bound, opts.epoch ?? 2,
|
|
42
|
+
opts.expired ? "2000-01-01 00:00:00" : null, opts.revoked ? "2000-01-01 00:00:00" : null]);
|
|
43
|
+
return tid;
|
|
44
|
+
}
|
|
45
|
+
function heartbeat(id: string, opts: { bound?: string | null; network?: string | null; alias?: string; age?: number } = {}) {
|
|
46
|
+
const n = db.get<any>("SELECT alias,network_id FROM nodes WHERE node_id=?1", id)!;
|
|
47
|
+
db.run(`INSERT INTO sessions(resume_id,alias,network_id,node_id,last_seen_at,status,cpu_cores,mem_total_gb,ip)
|
|
48
|
+
VALUES(?1,?2,?3,?4,?5,'idle',8,16,'10.1.1.1')`, [`s_lhs1109_${++sequence}`, opts.alias ?? n.alias,
|
|
49
|
+
opts.network === undefined ? n.network_id : opts.network, opts.bound === undefined ? id : opts.bound,
|
|
50
|
+
new Date(Date.now() - (opts.age ?? 0)).toISOString()]);
|
|
51
|
+
}
|
|
52
|
+
async function list(entry: "MCP" | "REST") {
|
|
53
|
+
if (entry === "REST") {
|
|
54
|
+
const r = await fetch(`${base}/api/host-supervisors?network_id=${net}`, { headers: { Authorization: `Bearer ${token}` } });
|
|
55
|
+
expect(r.status).toBe(200); return (await r.json() as any).daemons as any[];
|
|
56
|
+
}
|
|
57
|
+
const server = new McpServer({ name: "fixture", version: "0" }) as any;
|
|
58
|
+
let handler: any;
|
|
59
|
+
const original = server.tool.bind(server);
|
|
60
|
+
server.tool = (name: string, desc: string, schema: any, fn: any) => {
|
|
61
|
+
if (name === "list_host_supervisors") handler = fn;
|
|
62
|
+
return original(name, desc, schema, fn);
|
|
63
|
+
};
|
|
64
|
+
registerTools(server, undefined, null, user, null, false, null);
|
|
65
|
+
const result = await handler({ network_id: net });
|
|
66
|
+
const parsed = JSON.parse(result.content[0].text); expect(parsed.ok).toBe(true); return parsed.daemons as any[];
|
|
67
|
+
}
|
|
68
|
+
for (const entry of ["MCP", "REST"] as const) {
|
|
69
|
+
test(`${entry}: bound credentials survive stale token names and rotations dedupe`, async () => {
|
|
70
|
+
const id = node("renamed"); credential(id, { name: "lhs1109_oldname" }); credential(id); heartbeat(id);
|
|
71
|
+
const rows = await list(entry); expect(rows.length).toBe(1);
|
|
72
|
+
expect(rows[0]).toMatchObject({ daemon_node_id: id, online: true });
|
|
73
|
+
expect(JSON.stringify(rows)).not.toContain("hash_");
|
|
74
|
+
});
|
|
75
|
+
test(`${entry}: same-name foreign binding and missing bound node cannot authenticate daemon`, async () => {
|
|
76
|
+
const id = node("victim"), other = node("victim", foreign);
|
|
77
|
+
credential(id, { bound: other }); credential(id, { bound: "n_lhs1109_missing" }); heartbeat(id);
|
|
78
|
+
expect(await list(entry)).toEqual([]);
|
|
79
|
+
});
|
|
80
|
+
test(`${entry}: legacy owner and epoch-zero ownerless keep compatibility; squatter and new ownerless rejected`, async () => {
|
|
81
|
+
const good = node("owned"), old = node("old", net, null), squatter = node("squatter"), recent = node("recent", net, null);
|
|
82
|
+
credential(good, { bound: null }); credential(old, { bound: null, epoch: 0 });
|
|
83
|
+
credential(squatter, { bound: null, issuer: "u_foreign_fixture" }); credential(recent, { bound: null, epoch: 1 });
|
|
84
|
+
const ids = (await list(entry)).map(r => r.daemon_node_id).sort(); expect(ids).toEqual([good, old].sort());
|
|
85
|
+
});
|
|
86
|
+
test(`${entry}: same-alias sibling heartbeat cannot make stopped daemon online`, async () => {
|
|
87
|
+
const stopped = node("duplicate"), live = node("duplicate"); credential(stopped); credential(live); heartbeat(live);
|
|
88
|
+
const rows = await list(entry);
|
|
89
|
+
expect(rows.find(r => r.daemon_node_id === stopped)).toMatchObject({ online: false, last_seen_at: null });
|
|
90
|
+
expect(rows.find(r => r.daemon_node_id === live)).toMatchObject({ online: true });
|
|
91
|
+
});
|
|
92
|
+
test(`${entry}: null-ID heartbeat requires unique alias in its network`, async () => {
|
|
93
|
+
const unique = node("unique"), a = node("ambiguous"), b = node("ambiguous");
|
|
94
|
+
for (const id of [unique,a,b]) credential(id);
|
|
95
|
+
heartbeat(unique, { bound: null }); heartbeat(a, { bound: null });
|
|
96
|
+
const rows = await list(entry);
|
|
97
|
+
expect(rows.find(r => r.daemon_node_id === unique).online).toBe(true);
|
|
98
|
+
expect(rows.filter(r => r.daemon_node_id !== unique).map(r => r.online)).toEqual([false,false]);
|
|
99
|
+
});
|
|
100
|
+
test(`${entry}: null-network legacy heartbeat is accepted only for globally unique aliases`, async () => {
|
|
101
|
+
const unique = node("globalunique"), shared = node("globalshared"); node("globalshared", foreign);
|
|
102
|
+
credential(unique); credential(shared);
|
|
103
|
+
// Fresh sessions is NOT NULL. Exercise the historical nullable shape in
|
|
104
|
+
// an actual temporary SQL table, without changing the production schema
|
|
105
|
+
// or mocking returned rows. Only the heartbeat read uses this table;
|
|
106
|
+
// the production node/token/scoped SQL and both HTTP/MCP paths stay real.
|
|
107
|
+
db.exec("CREATE TEMP TABLE lhs1109_legacy_sessions AS SELECT * FROM sessions WHERE 0=1");
|
|
108
|
+
for (const id of [unique, shared]) {
|
|
109
|
+
const n = db.get<any>("SELECT alias FROM nodes WHERE node_id=?1", id)!;
|
|
110
|
+
db.run(`INSERT INTO lhs1109_legacy_sessions(resume_id,alias,network_id,node_id,last_seen_at,updated_at,status)
|
|
111
|
+
VALUES(?1,?2,NULL,NULL,?3,?3,'idle')`, [`s_lhs1109_${++sequence}`, n.alias, new Date().toISOString()]);
|
|
112
|
+
}
|
|
113
|
+
const original = db.all.bind(db);
|
|
114
|
+
db.all = ((sql: string, ...params: any[]) => original(sql.replace("FROM sessions s", "FROM lhs1109_legacy_sessions s"), ...params)) as any;
|
|
115
|
+
try {
|
|
116
|
+
const rows = await list(entry);
|
|
117
|
+
expect(rows.find(r => r.daemon_node_id === unique).online).toBe(true);
|
|
118
|
+
expect(rows.find(r => r.daemon_node_id === shared).online).toBe(false);
|
|
119
|
+
} finally {
|
|
120
|
+
db.all = original;
|
|
121
|
+
db.exec("DROP TABLE lhs1109_legacy_sessions");
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
test(`${entry}: bound heartbeat ignores stale alias but refuses wrong network and stale timestamps`, async () => {
|
|
125
|
+
const renamed = node("newalias"), wrong = node("wrongnet"), stale = node("stale");
|
|
126
|
+
for (const id of [renamed,wrong,stale]) credential(id);
|
|
127
|
+
heartbeat(renamed, { alias: "lhs1109_stalealias" }); heartbeat(wrong, { network: foreign }); heartbeat(stale, { age: 360_000 });
|
|
128
|
+
const rows = await list(entry);
|
|
129
|
+
expect(rows.find(r => r.daemon_node_id === renamed).online).toBe(true);
|
|
130
|
+
expect(rows.filter(r => r.daemon_node_id !== renamed).map(r => r.online)).toEqual([false,false]);
|
|
131
|
+
});
|
|
132
|
+
test(`${entry}: unbound duplicate-owner disambiguation uses authoritative recent session`, async () => {
|
|
133
|
+
const a = node("unboundduplicate"), b = node("unboundduplicate"); credential(a, { bound: null }); heartbeat(b);
|
|
134
|
+
const rows = await list(entry); expect(rows.length).toBe(1); expect(rows[0]).toMatchObject({ daemon_node_id: b, online: true });
|
|
135
|
+
});
|
|
136
|
+
test(`${entry}: deleted, revoked, expired and wrong-scope credentials excluded`, async () => {
|
|
137
|
+
for (const [label,opts] of [["expired",{ expired:true }],["revoked",{ revoked:true }],["scope",{ scope:"full" }],["deleted",{}]] as const) {
|
|
138
|
+
const id = node(label), tid = credential(id, opts); heartbeat(id);
|
|
139
|
+
if (label === "deleted") db.run("DELETE FROM api_tokens WHERE token_id=?1", [tid]);
|
|
140
|
+
}
|
|
141
|
+
expect(await list(entry)).toEqual([]);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
test("batched list performs three reads for many daemons and multiple scoped networks", () => {
|
|
145
|
+
for (let i=0;i<30;i++) { const id=node(`fleet${i}`, i%2 ? net : foreign); credential(id); heartbeat(id); }
|
|
146
|
+
const original = db.all.bind(db); let reads=0;
|
|
147
|
+
db.all = ((sql: string, ...params: any[]) => { reads++; return original(sql, ...params); }) as any;
|
|
148
|
+
try {
|
|
149
|
+
const rows = hostSupervisorIdentityRows("SELECT * FROM nodes WHERE network_id=?1 OR network_id=?2", [net,foreign]);
|
|
150
|
+
expect(rows.length).toBe(30); expect(reads).toBe(3);
|
|
151
|
+
} finally { db.all = original; }
|
|
152
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { db } from "./db.js";
|
|
2
|
+
import { resolveNodeCallerFromRows, type NodeCallerRow, type NodeCallerToken } from "./create-node.js";
|
|
3
|
+
import { parseDbTimestampMs } from "./db-timestamp.js";
|
|
4
|
+
|
|
5
|
+
type NodeRow = NodeCallerRow & Record<string, any>;
|
|
6
|
+
type SessionRow = {
|
|
7
|
+
node_id: string | null; alias: string; network_id: string | null;
|
|
8
|
+
last_seen_at: string | null; status: string | null;
|
|
9
|
+
cpu_cores: number | null; mem_total_gb: number | null; ip: string | null;
|
|
10
|
+
legacy_alias_count: number;
|
|
11
|
+
};
|
|
12
|
+
const key = (network: string, alias: string) => JSON.stringify([network, alias]);
|
|
13
|
+
const push = <T>(map: Map<string, T[]>, id: string, value: T) => {
|
|
14
|
+
const list = map.get(id) ?? []; list.push(value); map.set(id, list);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** The caller supplies a scoped nodes query, never an unchecked network id.
|
|
18
|
+
* Three SQL reads regardless of fleet size; no token secrets are selected.
|
|
19
|
+
* All node roles participate in legacy alias disambiguation.
|
|
20
|
+
*/
|
|
21
|
+
export function hostSupervisorIdentityRows(scopedNodesSql: string, params: any[]): NodeRow[] {
|
|
22
|
+
const nodes = db.all<NodeRow>(scopedNodesSql, ...params);
|
|
23
|
+
if (!nodes.length) return [];
|
|
24
|
+
const tokens = db.all<NodeCallerToken>(`
|
|
25
|
+
SELECT t.name, t.network_id, t.user_id, t.bound_node_id, t.node_identity_epoch
|
|
26
|
+
FROM api_tokens t
|
|
27
|
+
WHERE t.network_id IN (SELECT scoped.network_id FROM (${scopedNodesSql}) scoped)
|
|
28
|
+
AND t.scope='network' AND t.revoked_at IS NULL
|
|
29
|
+
AND (t.expires_at IS NULL OR t.expires_at > datetime('now'))
|
|
30
|
+
AND t.name LIKE 'node:%'
|
|
31
|
+
`, ...params);
|
|
32
|
+
const sessions = db.all<SessionRow>(`
|
|
33
|
+
SELECT s.node_id, s.alias, s.network_id, s.last_seen_at, s.status,
|
|
34
|
+
s.cpu_cores, s.mem_total_gb, s.ip,
|
|
35
|
+
CASE WHEN s.network_id IS NULL AND s.node_id IS NULL THEN
|
|
36
|
+
(SELECT COUNT(*) FROM nodes n WHERE n.alias=s.alias)
|
|
37
|
+
ELSE 0 END AS legacy_alias_count
|
|
38
|
+
FROM sessions s
|
|
39
|
+
WHERE s.network_id IN (SELECT scoped.network_id FROM (${scopedNodesSql}) scoped)
|
|
40
|
+
OR (s.network_id IS NULL AND (
|
|
41
|
+
s.alias IN (SELECT scoped.alias FROM (${scopedNodesSql}) scoped)
|
|
42
|
+
OR s.node_id IN (SELECT scoped.node_id FROM (${scopedNodesSql}) scoped)))
|
|
43
|
+
ORDER BY s.updated_at DESC
|
|
44
|
+
`, ...params);
|
|
45
|
+
const byId = new Map(nodes.map(n => [n.node_id, n]));
|
|
46
|
+
const byAlias = new Map<string, NodeRow[]>();
|
|
47
|
+
const byGlobalAlias = new Map<string, NodeRow[]>();
|
|
48
|
+
for (const n of nodes) {
|
|
49
|
+
push(byAlias, key(n.network_id, n.alias), n);
|
|
50
|
+
push(byGlobalAlias, n.alias, n);
|
|
51
|
+
}
|
|
52
|
+
const recent = new Map<string, string>();
|
|
53
|
+
for (const s of sessions) {
|
|
54
|
+
if (!s.network_id || !s.node_id) continue;
|
|
55
|
+
const id = key(s.network_id, s.alias);
|
|
56
|
+
if (!recent.has(id)) recent.set(id, s.node_id);
|
|
57
|
+
}
|
|
58
|
+
const credentialed = new Set<string>();
|
|
59
|
+
for (const t of tokens) {
|
|
60
|
+
if (!t.network_id) continue;
|
|
61
|
+
const bound = t.bound_node_id ? byId.get(t.bound_node_id) : null;
|
|
62
|
+
const rows = t.bound_node_id
|
|
63
|
+
? (bound?.network_id === t.network_id ? [bound] : [])
|
|
64
|
+
: byAlias.get(key(t.network_id, t.name.slice(5))) ?? [];
|
|
65
|
+
const caller = resolveNodeCallerFromRows(t, rows, recent.get(key(t.network_id, t.name.slice(5))) ?? null);
|
|
66
|
+
if (caller.ok && caller.kind === "node") credentialed.add(caller.nodeId);
|
|
67
|
+
}
|
|
68
|
+
const heartbeat = new Map<string, SessionRow>();
|
|
69
|
+
for (const s of sessions) {
|
|
70
|
+
let node: NodeRow | undefined;
|
|
71
|
+
if (s.node_id) {
|
|
72
|
+
node = byId.get(s.node_id);
|
|
73
|
+
if (s.network_id !== null && node?.network_id !== s.network_id) continue;
|
|
74
|
+
} else if (s.network_id) {
|
|
75
|
+
const matches = byAlias.get(key(s.network_id, s.alias)) ?? [];
|
|
76
|
+
if (matches.length === 1) node = matches[0];
|
|
77
|
+
} else if (Number(s.legacy_alias_count) === 1) {
|
|
78
|
+
node = byGlobalAlias.get(s.alias)?.[0];
|
|
79
|
+
}
|
|
80
|
+
if (!node || !s.last_seen_at || !Number.isFinite(parseDbTimestampMs(s.last_seen_at))) continue;
|
|
81
|
+
const previous = heartbeat.get(node.node_id);
|
|
82
|
+
if (!previous || parseDbTimestampMs(s.last_seen_at) > parseDbTimestampMs(previous.last_seen_at!)) {
|
|
83
|
+
heartbeat.set(node.node_id, s);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return nodes.filter(n => credentialed.has(n.node_id)).map(n => {
|
|
87
|
+
const s = heartbeat.get(n.node_id);
|
|
88
|
+
return { ...n, session_last_seen: s?.last_seen_at ?? null, session_status: s?.status ?? null,
|
|
89
|
+
session_cpu_cores: s?.cpu_cores ?? null, session_mem_total_gb: s?.mem_total_gb ?? null,
|
|
90
|
+
session_ip: s?.ip ?? null };
|
|
91
|
+
});
|
|
92
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// #973 — /api/host-supervisors surfaces the daemon's self-reported runtime
|
|
2
|
+
// version (`agent_node_version`).
|
|
3
|
+
//
|
|
4
|
+
// Why it needs a session join: nodes already send `version` in report_status
|
|
5
|
+
// (agent-node/src/cli.ts writes AGENT_NODE_VERSION) and the Hub stores it on the
|
|
6
|
+
// session row, which is why /api/status can show it. `nodes` has no version
|
|
7
|
+
// column, so the daemon list reads the newest session row for the same
|
|
8
|
+
// (network_id, node_id).
|
|
9
|
+
//
|
|
10
|
+
// 🔴 Absent stays absent: a daemon that never reported a version must NOT get a
|
|
11
|
+
// default, an empty string or the Hub's own version — "unknown" and "old" are
|
|
12
|
+
// different facts, and inventing one would make the client show a stale daemon
|
|
13
|
+
// as up to date.
|
|
14
|
+
import { describe, expect, test, beforeAll, afterAll } from "bun:test";
|
|
15
|
+
import "./require-explicit-test-db.js";
|
|
16
|
+
import { register, login } from "./auth.js";
|
|
17
|
+
import { db } from "./db.js";
|
|
18
|
+
|
|
19
|
+
let BASE = "";
|
|
20
|
+
let server: any = null;
|
|
21
|
+
let userToken = "";
|
|
22
|
+
let userNetworkId = "";
|
|
23
|
+
let userId = "";
|
|
24
|
+
|
|
25
|
+
beforeAll(async () => {
|
|
26
|
+
process.env.HOST = "127.0.0.1";
|
|
27
|
+
const suffix = `${Date.now()}_${Math.floor(Math.random() * 1000)}`;
|
|
28
|
+
const password = "DaemonVersionPw123Aa!";
|
|
29
|
+
const seed = register(`dver_seed_${suffix}`, password, undefined, "seed");
|
|
30
|
+
if (!seed.ok) throw new Error("seed failed");
|
|
31
|
+
db.run("UPDATE users SET role = 'admin' WHERE username = ?1", [`dver_seed_${suffix}`]);
|
|
32
|
+
const u = register(`dver_u_${suffix}`, password, undefined, "seed");
|
|
33
|
+
if (!u.ok || !u.token) throw new Error("user register failed");
|
|
34
|
+
userToken = u.token;
|
|
35
|
+
userNetworkId = u.network_id ?? "";
|
|
36
|
+
userId = login(`dver_u_${suffix}`, password).user!.user_id;
|
|
37
|
+
|
|
38
|
+
const { bootServer } = await import("./server.js");
|
|
39
|
+
server = bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
40
|
+
BASE = `http://127.0.0.1:${server.port}`;
|
|
41
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
afterAll(() => {
|
|
45
|
+
try { server?.stop?.(true); } catch {}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function seedDaemon(alias: string): void {
|
|
49
|
+
db.run(
|
|
50
|
+
`INSERT OR REPLACE INTO nodes (
|
|
51
|
+
node_id, node_name, alias, runtime, model, config_path,
|
|
52
|
+
channels, server, hostname, network_id,
|
|
53
|
+
config_revision, config_snapshot
|
|
54
|
+
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12)`,
|
|
55
|
+
[`dver_n_${alias}`, alias, alias, "claude-agent-sdk", "claude-sonnet-4-5",
|
|
56
|
+
"/tmp/cfg.json", "[]", "test-host", "test-host", userNetworkId,
|
|
57
|
+
0, JSON.stringify({ role: "host_supervisor" })],
|
|
58
|
+
);
|
|
59
|
+
db.run(
|
|
60
|
+
`INSERT OR REPLACE INTO api_tokens (
|
|
61
|
+
token_id, token_hash, user_id, network_id, name, scope
|
|
62
|
+
) VALUES (?1, ?2, ?3, ?4, ?5, ?6)`,
|
|
63
|
+
[`dver_t_${alias}`, `hash_${alias}`, userId, userNetworkId, `node:${alias}`, "network"],
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function seedSession(alias: string, version: string | null): void {
|
|
68
|
+
const now = new Date().toISOString();
|
|
69
|
+
db.run(
|
|
70
|
+
`INSERT OR REPLACE INTO sessions (
|
|
71
|
+
node_id, alias, network_id, registered_at, updated_at,
|
|
72
|
+
peer_reply_inbox_capable, rules_file_capable, skills_capable,
|
|
73
|
+
files_capable, logs_capable, version
|
|
74
|
+
) VALUES (?1, ?2, ?3, ?4, ?4, 1, 1, 1, 1, 1, ?5)`,
|
|
75
|
+
[`dver_n_${alias}`, alias, userNetworkId, now, version],
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function clearAll(): void {
|
|
80
|
+
db.run("DELETE FROM sessions WHERE network_id = ?1", [userNetworkId]);
|
|
81
|
+
db.run("DELETE FROM nodes WHERE network_id = ?1", [userNetworkId]);
|
|
82
|
+
db.run("DELETE FROM api_tokens WHERE network_id = ?1 AND name LIKE 'node:%'", [userNetworkId]);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function listDaemons(): Promise<any[]> {
|
|
86
|
+
const res = await fetch(`${BASE}/api/host-supervisors`, {
|
|
87
|
+
headers: { "Authorization": `Bearer ${userToken}` },
|
|
88
|
+
});
|
|
89
|
+
const body = await res.json();
|
|
90
|
+
if (!body.ok) throw new Error("list failed: " + JSON.stringify(body));
|
|
91
|
+
return body.daemons;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const find = (rows: any[], alias: string) => rows.find((r) => r.alias === alias)!;
|
|
95
|
+
|
|
96
|
+
describe("#973 — daemon list carries the self-reported runtime version", () => {
|
|
97
|
+
test("a daemon whose newest session reported a version exposes agent_node_version", async () => {
|
|
98
|
+
clearAll();
|
|
99
|
+
seedDaemon("versioned-a");
|
|
100
|
+
seedSession("versioned-a", "2.5.0-preview.155");
|
|
101
|
+
const d = find(await listDaemons(), "versioned-a");
|
|
102
|
+
expect(d.agent_node_version).toBe("2.5.0-preview.155");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("🔴 no session / no version → the field is ABSENT (never a default)", async () => {
|
|
106
|
+
clearAll();
|
|
107
|
+
seedDaemon("silent-a");
|
|
108
|
+
const d = find(await listDaemons(), "silent-a");
|
|
109
|
+
expect("agent_node_version" in d).toBe(false);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("an older session's version does not win over the newest one", async () => {
|
|
113
|
+
clearAll();
|
|
114
|
+
seedDaemon("newest-a");
|
|
115
|
+
const old = new Date(Date.now() - 60_000).toISOString();
|
|
116
|
+
const now = new Date().toISOString();
|
|
117
|
+
// Same (network_id, node_id) with two rows: the newest updated_at must win.
|
|
118
|
+
db.run(
|
|
119
|
+
`INSERT OR REPLACE INTO sessions (
|
|
120
|
+
node_id, alias, network_id, registered_at, updated_at,
|
|
121
|
+
peer_reply_inbox_capable, rules_file_capable, skills_capable,
|
|
122
|
+
files_capable, logs_capable, version
|
|
123
|
+
) VALUES (?1, ?2, ?3, ?4, ?5, 1, 1, 1, 1, 1, ?6)`,
|
|
124
|
+
["dver_n_newest-a", "newest-a", userNetworkId, old, old, "2.5.0-preview.146"],
|
|
125
|
+
);
|
|
126
|
+
db.run(
|
|
127
|
+
`INSERT OR REPLACE INTO sessions (
|
|
128
|
+
node_id, alias, network_id, registered_at, updated_at,
|
|
129
|
+
peer_reply_inbox_capable, rules_file_capable, skills_capable,
|
|
130
|
+
files_capable, logs_capable, version
|
|
131
|
+
) VALUES (?1, ?2, ?3, ?4, ?5, 1, 1, 1, 1, 1, ?6)`,
|
|
132
|
+
["dver_n_newest-a", "newest-a", userNetworkId, now, now, "2.5.0-preview.155"],
|
|
133
|
+
);
|
|
134
|
+
const d = find(await listDaemons(), "newest-a");
|
|
135
|
+
expect(d.agent_node_version).toBe("2.5.0-preview.155");
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { maybeGzipResponse, wantsGzip, isCompressibleResponse, trimLightTask, GZIP_MIN_BYTES, LIGHT_TASK_MAX_CHARS } from "./http-gzip";
|
|
3
|
+
|
|
4
|
+
const big = JSON.stringify({ sessions: Array.from({ length: 200 }, (_, i) => ({ alias: `节点${i}`, task: "x".repeat(50) })) });
|
|
5
|
+
const json = (body: string, extra: Record<string, string> = {}) =>
|
|
6
|
+
new Response(body, { status: 200, headers: { "Content-Type": "application/json; charset=utf-8", ...extra } });
|
|
7
|
+
const reqWith = (ae?: string, method = "GET") =>
|
|
8
|
+
new Request("http://hub/api/status?light=1", { method, headers: ae === undefined ? {} : { "Accept-Encoding": ae } });
|
|
9
|
+
|
|
10
|
+
test("wantsGzip reads Accept-Encoding, including q-values", () => {
|
|
11
|
+
expect(wantsGzip(reqWith("gzip, deflate, br"))).toBe(true);
|
|
12
|
+
expect(wantsGzip(reqWith("br;q=1.0, gzip;q=0.8"))).toBe(true);
|
|
13
|
+
expect(wantsGzip(reqWith("identity"))).toBe(false);
|
|
14
|
+
expect(wantsGzip(reqWith("gzip;q=0"))).toBe(false);
|
|
15
|
+
expect(wantsGzip(reqWith())).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("a large JSON body is gzipped only when the client asked, and round-trips", async () => {
|
|
19
|
+
const out = await maybeGzipResponse(reqWith("gzip"), json(big));
|
|
20
|
+
expect(out!.headers.get("Content-Encoding")).toBe("gzip");
|
|
21
|
+
expect(out!.headers.get("Vary")).toContain("Accept-Encoding");
|
|
22
|
+
const bytes = new Uint8Array(await out!.arrayBuffer());
|
|
23
|
+
expect(bytes.byteLength).toBeLessThan(big.length / 3);
|
|
24
|
+
expect(Number(out!.headers.get("Content-Length"))).toBe(bytes.byteLength);
|
|
25
|
+
expect(new TextDecoder().decode(Bun.gunzipSync(bytes))).toBe(big);
|
|
26
|
+
expect((out!.headers.get("Content-Type") || "").split(";")[0].trim()).toBe("application/json");
|
|
27
|
+
|
|
28
|
+
const plain = json(big);
|
|
29
|
+
expect(await maybeGzipResponse(reqWith(), plain)).toBe(plain); // untouched object
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("small, streamed, already-encoded, SSE, 204 and HEAD responses are left alone", async () => {
|
|
33
|
+
const small = json("{\"ok\":true}");
|
|
34
|
+
const outSmall = await maybeGzipResponse(reqWith("gzip"), small);
|
|
35
|
+
expect(outSmall!.headers.get("Content-Encoding")).toBeNull();
|
|
36
|
+
expect(await outSmall!.text()).toBe("{\"ok\":true}");
|
|
37
|
+
expect(GZIP_MIN_BYTES).toBe(1024);
|
|
38
|
+
|
|
39
|
+
const sse = new Response(new ReadableStream(), { headers: { "Content-Type": "text/event-stream" } });
|
|
40
|
+
expect(isCompressibleResponse(sse)).toBe(false);
|
|
41
|
+
expect(await maybeGzipResponse(reqWith("gzip"), sse)).toBe(sse);
|
|
42
|
+
|
|
43
|
+
const encoded = json(big, { "Content-Encoding": "br" });
|
|
44
|
+
expect(await maybeGzipResponse(reqWith("gzip"), encoded)).toBe(encoded);
|
|
45
|
+
|
|
46
|
+
const noContent = new Response(null, { status: 204 });
|
|
47
|
+
expect(await maybeGzipResponse(reqWith("gzip"), noContent)).toBe(noContent);
|
|
48
|
+
|
|
49
|
+
const head = json(big);
|
|
50
|
+
expect(await maybeGzipResponse(reqWith("gzip", "HEAD"), head)).toBe(head);
|
|
51
|
+
|
|
52
|
+
// /api/files downloads: Range replies and attachments keep their exact byte lengths (CI #509/#514 caught this)
|
|
53
|
+
const partial = new Response("x".repeat(4096), { status: 206, headers: { "Content-Type": "text/plain", "Content-Range": "bytes 0-4095/8192" } });
|
|
54
|
+
expect(await maybeGzipResponse(reqWith("gzip"), partial)).toBe(partial);
|
|
55
|
+
const attachment = new Response("y".repeat(4096), { status: 200, headers: { "Content-Type": "text/plain", "Content-Disposition": "attachment; filename=\"a.txt\"" } });
|
|
56
|
+
expect(await maybeGzipResponse(reqWith("gzip"), attachment)).toBe(attachment);
|
|
57
|
+
|
|
58
|
+
const binary = new Response(new Uint8Array(4096), { headers: { "Content-Type": "image/png" } });
|
|
59
|
+
expect(await maybeGzipResponse(reqWith("gzip"), binary)).toBe(binary);
|
|
60
|
+
|
|
61
|
+
expect(await maybeGzipResponse(reqWith("gzip"), undefined)).toBeUndefined();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("trimLightTask keeps a one-line preview under the cap", () => {
|
|
65
|
+
expect(trimLightTask(null)).toBeNull();
|
|
66
|
+
expect(trimLightTask(" ")).toBeNull();
|
|
67
|
+
expect(trimLightTask("a\n b")).toBe("a b");
|
|
68
|
+
const long = "字".repeat(LIGHT_TASK_MAX_CHARS + 40);
|
|
69
|
+
const t = trimLightTask(long)!;
|
|
70
|
+
expect(t.endsWith("…")).toBe(true);
|
|
71
|
+
expect([...t].length).toBe(LIGHT_TASK_MAX_CHARS + 1);
|
|
72
|
+
expect(trimLightTask("short")).toBe("short");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("a response marked reusable is gzipped once per key; unmarked ones every time; different keys never share bytes", async () => {
|
|
76
|
+
const { markGzipReusable, gzipCacheStats, __resetGzipCacheForTest } = await import("./http-gzip");
|
|
77
|
+
__resetGzipCacheForTest();
|
|
78
|
+
const first = await maybeGzipResponse(reqWith("gzip"), markGzipReusable(json(big), "W/\"k1\""));
|
|
79
|
+
const second = await maybeGzipResponse(reqWith("gzip"), markGzipReusable(json(big), "W/\"k1\""));
|
|
80
|
+
expect(gzipCacheStats).toEqual({ hits: 1, misses: 1 });
|
|
81
|
+
const a = new Uint8Array(await first!.arrayBuffer());
|
|
82
|
+
const b = new Uint8Array(await second!.arrayBuffer());
|
|
83
|
+
expect(new TextDecoder().decode(Bun.gunzipSync(b))).toBe(big);
|
|
84
|
+
expect(Buffer.from(b).equals(Buffer.from(a))).toBe(true);
|
|
85
|
+
expect(Number(second!.headers.get("Content-Length"))).toBe(b.byteLength);
|
|
86
|
+
const other = big.replace("节点0", "节点X");
|
|
87
|
+
const third = await maybeGzipResponse(reqWith("gzip"), markGzipReusable(json(other), "W/\"k2\""));
|
|
88
|
+
expect(new TextDecoder().decode(Bun.gunzipSync(new Uint8Array(await third!.arrayBuffer())))).toBe(other);
|
|
89
|
+
await maybeGzipResponse(reqWith("gzip"), json(big));
|
|
90
|
+
expect(gzipCacheStats).toEqual({ hits: 1, misses: 2 });
|
|
91
|
+
// 没要 gzip 的客户端照旧拿原样正文,不碰缓存
|
|
92
|
+
const plain = markGzipReusable(json(big), "W/\"k1\"");
|
|
93
|
+
expect(await maybeGzipResponse(reqWith(), plain)).toBe(plain);
|
|
94
|
+
});
|