@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,154 @@
|
|
|
1
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
2
|
+
import { createNetworkTokenForNode, register } from "./auth.js";
|
|
3
|
+
import { db, syncScheduledRunForTask } from "./db.js";
|
|
4
|
+
import { runDueScheduledTasks } from "./scheduled-tasks.js";
|
|
5
|
+
|
|
6
|
+
if (!process.env.COMMHUB_DB) throw new Error("test1274 requires an explicit disposable SQLite COMMHUB_DB");
|
|
7
|
+
let server: any, base = "", network = "", ownerToken = "", ownerId = "";
|
|
8
|
+
const stamp = Date.now(), nodes: Record<string, { id: string; alias: string; token: string; tokenId: string }> = {};
|
|
9
|
+
async function rest(token: string, method: string, path: string, body?: unknown) {
|
|
10
|
+
const r = await fetch(base + path, { method, headers: { Authorization: `Bearer ${token}`,
|
|
11
|
+
"Content-Type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body) });
|
|
12
|
+
return { status: r.status, body: await r.json() as any };
|
|
13
|
+
}
|
|
14
|
+
async function mcp(token: string, name: string, args: Record<string, unknown>) {
|
|
15
|
+
const r = await fetch(base + "/mcp", { method: "POST", headers: { Authorization: `Bearer ${token}`,
|
|
16
|
+
"Content-Type": "application/json", Accept: "application/json, text/event-stream" },
|
|
17
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name, arguments: args } }) });
|
|
18
|
+
const raw = await r.text(), line = raw.split("\n").find(x => x.startsWith("data: "));
|
|
19
|
+
const envelope = JSON.parse(line ? line.slice(6) : raw);
|
|
20
|
+
try { return JSON.parse(envelope.result.content[0].text); }
|
|
21
|
+
catch { return { ok: false, transportError: true }; }
|
|
22
|
+
}
|
|
23
|
+
const readRun = (taskId: string) => db.get<any>(
|
|
24
|
+
"SELECT run_id, schedule_id, status, work_outcome, work_outcome_node_id, schedule_revision FROM scheduled_task_runs WHERE task_id = ?1 AND network_id = ?2", taskId, network)!;
|
|
25
|
+
const readTask = (taskId: string) => db.get<any>("SELECT status, result FROM tasks WHERE task_id = ?1", taskId)!;
|
|
26
|
+
const countReplies = (taskId: string) => db.get<{ n: number }>("SELECT COUNT(*) AS n FROM inbox WHERE in_reply_to = ?1 AND type = 'reply'", taskId)!.n;
|
|
27
|
+
async function fire() {
|
|
28
|
+
const created = await rest(ownerToken, "POST", "/api/scheduled-tasks", { network_id: network,
|
|
29
|
+
name: `test1274-${crypto.randomUUID()}`, target_node_id: nodes.a.id, task: "fixture1274 work",
|
|
30
|
+
schedule: { type: "interval", every_seconds: 120 }, timezone: "UTC" });
|
|
31
|
+
expect(created.status).toBe(201);
|
|
32
|
+
const scheduleId = created.body.schedule.schedule_id;
|
|
33
|
+
db.run("UPDATE scheduled_tasks SET next_run_at = ?1 WHERE schedule_id != ?2", [new Date(Date.now() + 86400_000).toISOString(), scheduleId]);
|
|
34
|
+
db.run("UPDATE scheduled_tasks SET next_run_at = ?1 WHERE schedule_id = ?2", [new Date(Date.now() - 1000).toISOString(), scheduleId]);
|
|
35
|
+
await runDueScheduledTasks();
|
|
36
|
+
const run = db.get<any>("SELECT task_id FROM scheduled_task_runs WHERE schedule_id = ?1", scheduleId)!;
|
|
37
|
+
expect(run.task_id).toBeTruthy();
|
|
38
|
+
return { taskId: run.task_id as string, scheduleId };
|
|
39
|
+
}
|
|
40
|
+
const reply = (taskId: string, meta?: unknown, status = "replied", token = nodes.a.token, extra = {}) =>
|
|
41
|
+
mcp(token, "send_reply", { in_reply_to: taskId, text: "本轮无新增", status, ...(meta === undefined ? {} : { meta }), ...extra });
|
|
42
|
+
const cadence = (id: string) => db.get<any>("SELECT next_run_at, last_run_at, revision, schedule_json, target_node_id FROM scheduled_tasks WHERE schedule_id = ?1", id)!;
|
|
43
|
+
|
|
44
|
+
beforeAll(async () => {
|
|
45
|
+
const owner = register(`work_owner_${stamp}`, "Fixture1274Only!x"); ownerToken = owner.token!;
|
|
46
|
+
network = owner.network_id!; ownerId = owner.user!.user_id;
|
|
47
|
+
for (const key of ["a", "b"]) {
|
|
48
|
+
const id = `n_work_${key}_${stamp}`, alias = `work-${key}-${stamp}`;
|
|
49
|
+
const token = createNetworkTokenForNode(ownerId, network, alias, id); expect(token.ok).toBe(true);
|
|
50
|
+
nodes[key] = { id, alias, token: token.token!, tokenId: token.token_id! };
|
|
51
|
+
db.run("INSERT INTO sessions (resume_id, alias, status, node_id, network_id) VALUES (?1, ?2, 'idle', ?3, ?4)", [`r_${id}`, alias, id, network]);
|
|
52
|
+
}
|
|
53
|
+
const mod = await import("./server.js"); server = mod.bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
54
|
+
base = `http://127.0.0.1:${server.port}`;
|
|
55
|
+
}, 30_000);
|
|
56
|
+
afterAll(() => server?.stop?.(true));
|
|
57
|
+
|
|
58
|
+
describe("#1274 exact successful scheduler work outcomes over real HTTP/MCP", () => {
|
|
59
|
+
test("explicit no_changes persists with the same successful run and is readable; cadence stays unchanged", async () => {
|
|
60
|
+
const { taskId, scheduleId } = await fire(), before = cadence(scheduleId);
|
|
61
|
+
expect(readRun(taskId).schedule_revision).toBe(before.revision);
|
|
62
|
+
const out = await reply(taskId, { scheduled_work_outcome: "no_changes", scheduled_run_id: "forged-and-ignored" });
|
|
63
|
+
expect(out.ok).toBe(true); expect(out.scheduled_work_outcome).toBe("no_changes");
|
|
64
|
+
expect(readTask(taskId).status).toBe("replied");
|
|
65
|
+
expect(readRun(taskId)).toMatchObject({ status: "replied", work_outcome: "no_changes", work_outcome_node_id: nodes.a.id });
|
|
66
|
+
expect(cadence(scheduleId)).toEqual(before);
|
|
67
|
+
const history = await rest(ownerToken, "GET", `/api/scheduled-tasks/${scheduleId}/runs`);
|
|
68
|
+
expect(history.status).toBe(200);
|
|
69
|
+
expect(history.body.runs[0]).toMatchObject({ task_id: taskId, work_outcome: "no_changes", schedule_revision: before.revision, work_outcome_node_id: nodes.a.id });
|
|
70
|
+
});
|
|
71
|
+
test("changed is explicit even when the reply's natural-language text says no changes", async () => {
|
|
72
|
+
const { taskId } = await fire(); expect((await reply(taskId, { scheduled_work_outcome: "changed" })).ok).toBe(true);
|
|
73
|
+
expect(readRun(taskId).work_outcome).toBe("changed");
|
|
74
|
+
});
|
|
75
|
+
test("legacy success and empty-looking text remain unknown with unchanged response shape", async () => {
|
|
76
|
+
const { taskId } = await fire(), out = await reply(taskId);
|
|
77
|
+
expect(out.ok).toBe(true); expect(out.scheduled_work_outcome).toBeUndefined();
|
|
78
|
+
expect(readRun(taskId)).toMatchObject({ status: "replied", work_outcome: null, work_outcome_node_id: null });
|
|
79
|
+
});
|
|
80
|
+
test("malformed, failed and cancelled signals do not write; ordinary terminal failures stay unknown", async () => {
|
|
81
|
+
for (const [status, value] of [["replied", null], ["replied", "empty"], ["failed", "no_changes"], ["cancelled", "no_changes"]]) {
|
|
82
|
+
const { taskId } = await fire(); expect((await reply(taskId, { scheduled_work_outcome: value }, status!)).ok).toBe(false);
|
|
83
|
+
expect(readTask(taskId).status).toBe("delivered"); expect(countReplies(taskId)).toBe(0);
|
|
84
|
+
expect((await reply(taskId, undefined, status!)).ok).toBe(true); expect(readRun(taskId).work_outcome).toBeNull();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
test("sibling node and a human token cannot classify the assigned node's run", async () => {
|
|
88
|
+
const { taskId } = await fire();
|
|
89
|
+
expect((await reply(taskId, { scheduled_work_outcome: "no_changes" }, "replied", nodes.b.token)).ok).toBe(false);
|
|
90
|
+
expect((await reply(taskId, { scheduled_work_outcome: "no_changes" }, "replied", ownerToken)).ok).toBe(false);
|
|
91
|
+
expect(readTask(taskId).status).toBe("delivered"); expect(readRun(taskId).work_outcome).toBeNull(); expect(countReplies(taskId)).toBe(0);
|
|
92
|
+
});
|
|
93
|
+
test("a foreign network token cannot classify or terminalize the run", async () => {
|
|
94
|
+
const { taskId } = await fire(), foreign = register(`work_foreign_${crypto.randomUUID()}`, "Fixture1274Only!x");
|
|
95
|
+
const token = createNetworkTokenForNode(foreign.user!.user_id, foreign.network_id!, `foreign-${crypto.randomUUID()}`, `n_${crypto.randomUUID()}`);
|
|
96
|
+
expect((await reply(taskId, { scheduled_work_outcome: "no_changes" }, "replied", token.token!)).ok).toBe(false);
|
|
97
|
+
expect(readTask(taskId).status).toBe("delivered"); expect(countReplies(taskId)).toBe(0);
|
|
98
|
+
});
|
|
99
|
+
test("a legacy unbound node token can still reply normally but cannot report a work signal", async () => {
|
|
100
|
+
const { taskId } = await fire();
|
|
101
|
+
db.run("UPDATE api_tokens SET bound_node_id = NULL WHERE token_id = ?1 AND network_id = ?2", [nodes.a.tokenId, network]);
|
|
102
|
+
try {
|
|
103
|
+
expect((await reply(taskId, { scheduled_work_outcome: "no_changes" })).ok).toBe(false);
|
|
104
|
+
expect((await reply(taskId)).ok).toBe(true); expect(readRun(taskId).work_outcome).toBeNull();
|
|
105
|
+
} finally { db.run("UPDATE api_tokens SET bound_node_id = ?1 WHERE token_id = ?2 AND network_id = ?3", [nodes.a.id, nodes.a.tokenId, network]); }
|
|
106
|
+
});
|
|
107
|
+
test("forged schedule metadata on an ordinary task cannot become an authoritative occurrence", async () => {
|
|
108
|
+
const { scheduleId } = await fire(); const sent = await rest(ownerToken, "POST", "/api/task", { network_id: network, alias: nodes.a.alias, task: "ordinary1274" });
|
|
109
|
+
expect(sent.status).toBe(200);
|
|
110
|
+
expect((await reply(sent.body.task_id, { scheduled_work_outcome: "no_changes", scheduled_task_id: scheduleId })).ok).toBe(false);
|
|
111
|
+
expect(readTask(sent.body.task_id).status).toBe("delivered"); expect(countReplies(sent.body.task_id)).toBe(0);
|
|
112
|
+
});
|
|
113
|
+
test("multiple authoritative bindings refuse instead of fanning one outcome into two runs", async () => {
|
|
114
|
+
const { taskId, scheduleId } = await fire(), run = readRun(taskId), duplicate = `srun_dup_${crypto.randomUUID()}`;
|
|
115
|
+
db.run("INSERT INTO scheduled_task_runs (run_id, schedule_id, network_id, scheduled_for, task_id, status) VALUES (?1, ?2, ?3, ?4, ?5, 'delivered')", [duplicate, scheduleId, network, new Date(Date.now() + 86400_000).toISOString(), taskId]);
|
|
116
|
+
try { expect((await reply(taskId, { scheduled_work_outcome: "no_changes" })).error).toBe("scheduled_work_outcome_run_unresolved");
|
|
117
|
+
expect(readTask(taskId).status).toBe("delivered"); expect(countReplies(taskId)).toBe(0); }
|
|
118
|
+
finally { db.run("DELETE FROM scheduled_task_runs WHERE run_id = ?1", duplicate); }
|
|
119
|
+
expect(readRun(taskId).run_id).toBe(run.run_id); expect(readRun(taskId).work_outcome).toBeNull();
|
|
120
|
+
});
|
|
121
|
+
test("expired/late receipts never classify a run or rewrite its original terminal state", async () => {
|
|
122
|
+
const { taskId } = await fire(), thread_id = `thread_${crypto.randomUUID()}`, turn_id = `turn_${crypto.randomUUID()}`;
|
|
123
|
+
db.run("UPDATE tasks SET status = 'expired', thread_id = ?1, turn_id = ?2, completed_at = datetime('now') WHERE task_id = ?3", [thread_id, turn_id, taskId]); syncScheduledRunForTask(taskId, network);
|
|
124
|
+
expect((await reply(taskId, { scheduled_work_outcome: "no_changes" }, "replied", nodes.a.token, { thread_id, turn_id })).error).toBe("scheduled_work_outcome_terminal");
|
|
125
|
+
expect((await reply(taskId, undefined, "replied", nodes.a.token, { thread_id, turn_id })).late).toBe(true);
|
|
126
|
+
expect(readTask(taskId).status).toBe("expired"); expect(readRun(taskId)).toMatchObject({ status: "expired", work_outcome: null });
|
|
127
|
+
});
|
|
128
|
+
test("success cannot retry; an expired fixture task clears stale outcome on retry and later failure", async () => {
|
|
129
|
+
const { taskId } = await fire(); expect((await reply(taskId, { scheduled_work_outcome: "no_changes" })).ok).toBe(true);
|
|
130
|
+
expect((await mcp(ownerToken, "retry_task", { task_id: taskId, network_id: network })).ok).toBe(false);
|
|
131
|
+
// Fixture-only legacy/corrupt terminal injection: preserve the stale run
|
|
132
|
+
// signal deliberately so the retry clearing branch is load-bearing.
|
|
133
|
+
db.run("UPDATE tasks SET status = 'expired' WHERE task_id = ?1", taskId);
|
|
134
|
+
expect((await mcp(ownerToken, "retry_task", { task_id: taskId, network_id: network })).ok).toBe(true);
|
|
135
|
+
expect(readRun(taskId)).toMatchObject({ status: "delivered", work_outcome: null, work_outcome_node_id: null });
|
|
136
|
+
expect((await reply(taskId, undefined, "failed")).ok).toBe(true); expect(readRun(taskId)).toMatchObject({ status: "failed", work_outcome: null });
|
|
137
|
+
});
|
|
138
|
+
test("injected outcome write failure rolls back task, inbox and run atomically", async () => {
|
|
139
|
+
const { taskId } = await fire(), run = readRun(taskId);
|
|
140
|
+
db.exec(`CREATE TRIGGER test1274_outcome_fault BEFORE UPDATE OF work_outcome ON scheduled_task_runs WHEN NEW.run_id = '${run.run_id}' AND NEW.work_outcome IS NOT NULL BEGIN SELECT RAISE(ABORT, 'test1274_fault'); END`);
|
|
141
|
+
try { expect((await reply(taskId, { scheduled_work_outcome: "no_changes" })).ok).not.toBe(true); }
|
|
142
|
+
finally { db.exec("DROP TRIGGER test1274_outcome_fault"); }
|
|
143
|
+
expect(readTask(taskId)).toMatchObject({ status: "delivered", result: null });
|
|
144
|
+
expect(readRun(taskId)).toMatchObject({ status: "delivered", work_outcome: null }); expect(countReplies(taskId)).toBe(0);
|
|
145
|
+
expect((await reply(taskId, { scheduled_work_outcome: "changed" })).ok).toBe(true);
|
|
146
|
+
});
|
|
147
|
+
test("a later schedule edit cannot relabel the dispatch revision; history alone grants no backoff", async () => {
|
|
148
|
+
const { taskId, scheduleId } = await fire(), revision = readRun(taskId).schedule_revision;
|
|
149
|
+
const edit = await rest(ownerToken, "PATCH", `/api/scheduled-tasks/${scheduleId}`, { revision, name: "edited1274" }); expect(edit.status).toBe(200);
|
|
150
|
+
const before = cadence(scheduleId); expect(before.revision).toBe(revision + 1);
|
|
151
|
+
expect((await reply(taskId, { scheduled_work_outcome: "no_changes" })).ok).toBe(true);
|
|
152
|
+
expect(readRun(taskId).schedule_revision).toBe(revision); expect(cadence(scheduleId)).toEqual(before);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { db } from "./db.js";
|
|
2
|
+
|
|
3
|
+
export type ScheduledWorkOutcome = "changed" | "no_changes";
|
|
4
|
+
export function parseScheduledWorkOutcome(meta: unknown, status: string):
|
|
5
|
+
{ ok: true; outcome?: ScheduledWorkOutcome } | { ok: false; error: string } {
|
|
6
|
+
if (!meta || typeof meta !== "object" || Array.isArray(meta)
|
|
7
|
+
|| !Object.hasOwn(meta, "scheduled_work_outcome")) return { ok: true };
|
|
8
|
+
const outcome = (meta as Record<string, unknown>).scheduled_work_outcome;
|
|
9
|
+
if (outcome !== "changed" && outcome !== "no_changes")
|
|
10
|
+
return { ok: false, error: "invalid_scheduled_work_outcome" };
|
|
11
|
+
if (status !== "replied") return { ok: false, error: "scheduled_work_outcome_requires_success" };
|
|
12
|
+
return { ok: true, outcome };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type Binding = { run_id: string; schedule_id: string; task_id: string; network_id: string; node_id: string };
|
|
16
|
+
/** Called within the normal reply transaction, after the existing sender and
|
|
17
|
+
* recipient checks. Caller metadata never supplies schedule/run bindings. */
|
|
18
|
+
export function qualifyScheduledWorkOutcome(taskId: string, networkId: string, nodeId: string | null):
|
|
19
|
+
{ ok: true; binding: Binding } | { ok: false; error: string } {
|
|
20
|
+
if (!nodeId) return { ok: false, error: "scheduled_work_outcome_bound_node_required" };
|
|
21
|
+
if (db.transactionalFeaturesRefusal !== null)
|
|
22
|
+
return { ok: false, error: "scheduled_work_outcome_backend_unsupported" };
|
|
23
|
+
const task = db.get<{ to_node_id: string | null; from_name: string; status: string }>(
|
|
24
|
+
"SELECT to_node_id, from_name, status FROM tasks WHERE task_id = ?1 AND network_id = ?2", taskId, networkId);
|
|
25
|
+
if (!task || task.to_node_id !== nodeId || task.from_name !== "scheduler"
|
|
26
|
+
|| !["created", "delivered", "acked", "running"].includes(task.status))
|
|
27
|
+
return { ok: false, error: "scheduled_work_outcome_task_not_owned" };
|
|
28
|
+
const runs = db.all<{ run_id: string; schedule_id: string; status: string; work_outcome: string | null }>(
|
|
29
|
+
`SELECT r.run_id, r.schedule_id, r.status, r.work_outcome FROM scheduled_task_runs r
|
|
30
|
+
WHERE r.task_id = ?1 AND r.network_id = ?2`, taskId, networkId);
|
|
31
|
+
if (runs.length !== 1 || !["queued", "delivered"].includes(runs[0].status) || runs[0].work_outcome !== null)
|
|
32
|
+
return { ok: false, error: "scheduled_work_outcome_run_unresolved" };
|
|
33
|
+
if (!db.get("SELECT schedule_id FROM scheduled_tasks WHERE schedule_id = ?1 AND network_id = ?2", runs[0].schedule_id, networkId))
|
|
34
|
+
return { ok: false, error: "scheduled_work_outcome_run_unresolved" };
|
|
35
|
+
return { ok: true, binding: { run_id: runs[0].run_id, schedule_id: runs[0].schedule_id,
|
|
36
|
+
task_id: taskId, network_id: networkId, node_id: nodeId } };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The task has just reached replied in this same transaction. An outcome
|
|
40
|
+
* write failure must roll back task, inbox and run together. No cadence write. */
|
|
41
|
+
export function saveScheduledWorkOutcome(binding: Binding, outcome: ScheduledWorkOutcome): void {
|
|
42
|
+
const result = db.run(
|
|
43
|
+
`UPDATE scheduled_task_runs SET work_outcome = ?1, work_outcome_node_id = ?6
|
|
44
|
+
WHERE run_id = ?2 AND schedule_id = ?3 AND task_id = ?4 AND network_id = ?5
|
|
45
|
+
AND work_outcome IS NULL AND status IN ('queued', 'delivered')
|
|
46
|
+
AND EXISTS (SELECT 1 FROM tasks t WHERE t.task_id = ?4 AND t.network_id = ?5
|
|
47
|
+
AND t.to_node_id = ?6 AND t.from_name = 'scheduler' AND t.status = 'replied')`,
|
|
48
|
+
[outcome, binding.run_id, binding.schedule_id, binding.task_id, binding.network_id, binding.node_id]);
|
|
49
|
+
if (result.changes !== 1) throw new Error("scheduled_work_outcome_atomic_write_failed");
|
|
50
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Short-lived management lane, not task/message text and not a secret archive.
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { db } from './db';
|
|
4
|
+
import { getUserNetworkRole } from './auth';
|
|
5
|
+
import { providerScanTargets } from './daemon-provider-snapshots';
|
|
6
|
+
import { validScopedSecretKey } from './shared/scoped-secret-contract';
|
|
7
|
+
import { observeSecretWrite, transportOf } from './env-transport-gate.js';
|
|
8
|
+
import { secretTransportVerdict } from './env-transport-policy.js';
|
|
9
|
+
import { vaultGet } from './vault';
|
|
10
|
+
type Human = { userId?: string | null; isNode: boolean; networkId: string | null };
|
|
11
|
+
type Daemon = { ok: false; error: string } | { ok: true; networkId: string; daemonNodeId: string; daemonAlias: string };
|
|
12
|
+
type Request = { request_id: string; network_id: string; daemon_node_id: string | null; node_id: string | null;
|
|
13
|
+
action: 'list' | 'put' | 'delete'; key?: string; value?: string; revision?: number;
|
|
14
|
+
status: 'pending' | 'succeeded' | 'failed' | 'expired'; expires_at: number; snapshot?: any; error?: string };
|
|
15
|
+
const requests = new Map<string, Request>();
|
|
16
|
+
const denied = (error: string) => ({ ok: false as const, error });
|
|
17
|
+
function authorize(h: Human) {
|
|
18
|
+
return h.isNode || !h.userId ? denied('user_token_required') : !h.networkId
|
|
19
|
+
|| !['owner','admin'].includes(getUserNetworkRole(h.userId, h.networkId) ?? '') ? denied('secret_admin_required') : null;
|
|
20
|
+
}
|
|
21
|
+
function daemonSupported(network: string, daemon: string) {
|
|
22
|
+
const row = db.get<{ config_snapshot: string }>('SELECT config_snapshot FROM nodes WHERE network_id=?1 AND node_id=?2', network, daemon);
|
|
23
|
+
try { const s = JSON.parse(row?.config_snapshot ?? '{}'); return s.role === 'host_supervisor' && s.scoped_secrets_capable === true; } catch { return false; }
|
|
24
|
+
}
|
|
25
|
+
function expire() {
|
|
26
|
+
for (const [id,r] of requests) {
|
|
27
|
+
if (r.expires_at < Date.now() && r.status === 'pending') { r.status = 'expired'; delete r.value; }
|
|
28
|
+
if (r.expires_at + 600_000 < Date.now()) requests.delete(id);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const timer = setInterval(expire, 10_000); timer.unref();
|
|
32
|
+
function nodeSupported(network: string, node: string) {
|
|
33
|
+
const row = db.get<{ config_snapshot: string }>('SELECT config_snapshot FROM nodes WHERE network_id=?1 AND node_id=?2', network, node);
|
|
34
|
+
try { return JSON.parse(row?.config_snapshot ?? '{}').node_secrets_capable === true; } catch { return false; }
|
|
35
|
+
}
|
|
36
|
+
// Independent node lane: no supervisor lookup, binding, or Daemon credential.
|
|
37
|
+
//
|
|
38
|
+
// `fromVault`(2026-11-01,#3148)—— **把保险库里的值直接推给这个节点**,调用方不必再持有明文。
|
|
39
|
+
//
|
|
40
|
+
// 背景:RFC-028 的保险库是「只进不出」——`list_network_secrets` 只回键名,没有任何取值接口。
|
|
41
|
+
// 这是对的:给 agent 一个读口,等于把整个网络的密钥变成任何一次 prompt 注入都能 dump 的东西。
|
|
42
|
+
// 但它带来一个真实的死结(admin 2026-11-01 在客户端里撞到):
|
|
43
|
+
//
|
|
44
|
+
// 密钥已经在保险库里了,可**没有任何路径**把它送到真正要用的那个进程;
|
|
45
|
+
// 于是人只能把明文再复制一遍,或者干脆写进工作区文件 —— 两条都比保险库更差。
|
|
46
|
+
//
|
|
47
|
+
// 所以这里补的是**流向**而不是**读权**:值从保险库直接写进目标节点的那次请求,
|
|
48
|
+
// 调用方(必须是 owner/admin)只提供键名。读侧仍然拿不到任何明文:
|
|
49
|
+
// · getScopedSecrets 只回 status/snapshot/error
|
|
50
|
+
// · 节点 ack 回来的 snapshot 里只有 {key, source},没有值
|
|
51
|
+
export function requestNodeSecrets(h: Human, node: string, action: Request['action'], key?: string, value?: string, revision?: number, fromVault?: boolean) {
|
|
52
|
+
const refusal = authorize(h); if (refusal) return refusal;
|
|
53
|
+
if (!nodeSupported(h.networkId!, node)) return denied('node_secrets_upgrade_required');
|
|
54
|
+
// from_vault 只在 put 上有意义:list/delete 没有值可推。
|
|
55
|
+
if (fromVault && action !== 'put') return denied('invalid_secret_input');
|
|
56
|
+
if (fromVault && value !== undefined) return denied('invalid_secret_input');
|
|
57
|
+
if (fromVault) {
|
|
58
|
+
if (!validScopedSecretKey(key)) return denied('invalid_secret_input');
|
|
59
|
+
// 保险库里没有这个名字 ⇒ 明确说「没有」,不要回一个看起来成功的请求。
|
|
60
|
+
const fromVaultValue = vaultGet(h.networkId!, key!);
|
|
61
|
+
if (typeof fromVaultValue !== 'string' || !fromVaultValue) return denied('vault_key_missing');
|
|
62
|
+
value = fromVaultValue;
|
|
63
|
+
}
|
|
64
|
+
if (action !== 'list' && (!validScopedSecretKey(key) || !Number.isSafeInteger(revision) || revision! < 0
|
|
65
|
+
|| (action === 'put' && (typeof value !== 'string' || !value || Buffer.byteLength(value) > 8192 || value.includes('\0'))))) return denied('invalid_secret_input');
|
|
66
|
+
expire();
|
|
67
|
+
// #1510 — transport gate (log-only by default). A `put` carries the secret, so
|
|
68
|
+
// that is the only action worth observing; delete/list leak nothing.
|
|
69
|
+
if (action === 'put') {
|
|
70
|
+
const transport = transportOf(h.networkId!, node);
|
|
71
|
+
const verdict = secretTransportVerdict(transport);
|
|
72
|
+
if (verdict) return denied(verdict);
|
|
73
|
+
// 记录的是**来源**,不是值:from_vault 的注入要能从审计里区分出来。
|
|
74
|
+
observeSecretWrite(h.networkId!, node, `node_secret_${action}${fromVault ? '_from_vault' : ''}`);
|
|
75
|
+
}
|
|
76
|
+
if ([...requests.values()].some(r => r.network_id === h.networkId && r.daemon_node_id === null && r.node_id === node && r.status === 'pending')) return denied('secret_store_busy');
|
|
77
|
+
if (requests.size >= 1000) return denied('secret_queue_busy');
|
|
78
|
+
const r: Request = { request_id: `nsk_${randomUUID()}`, network_id: h.networkId!, daemon_node_id: null,
|
|
79
|
+
node_id: node, action, ...(action === 'list' ? {} : { key, revision, ...(action === 'put' ? { value } : {}) }),
|
|
80
|
+
expires_at: Date.now() + 120_000, status: 'pending' };
|
|
81
|
+
requests.set(r.request_id, r);
|
|
82
|
+
return { ok: true as const, request_id: r.request_id, status: r.status, expires_at: r.expires_at };
|
|
83
|
+
}
|
|
84
|
+
export function pullNodeSecrets(d: Daemon) {
|
|
85
|
+
if (!d.ok || !nodeSupported(d.networkId, d.daemonNodeId)) return denied('caller_not_a_secret_node');
|
|
86
|
+
expire();
|
|
87
|
+
return { ok: true, requests: [...requests.values()].filter(r => r.network_id === d.networkId && r.daemon_node_id === null
|
|
88
|
+
&& r.node_id === d.daemonNodeId && r.status === 'pending').map(({ status, snapshot, error, ...input }) => input) };
|
|
89
|
+
}
|
|
90
|
+
export function ackNodeSecrets(d: Daemon, id: string, snapshot: any, failed = false) {
|
|
91
|
+
if (!d.ok || !nodeSupported(d.networkId, d.daemonNodeId)) return denied('caller_not_a_secret_node');
|
|
92
|
+
expire(); const r = requests.get(id);
|
|
93
|
+
if (!r || r.network_id !== d.networkId || r.daemon_node_id !== null || r.node_id !== d.daemonNodeId) return denied('request_not_found');
|
|
94
|
+
if (r.status !== 'pending') return { ok: r.status === 'succeeded' || r.status === 'failed', status: r.status };
|
|
95
|
+
if (!failed) {
|
|
96
|
+
if (!snapshot || Object.keys(snapshot).some(k => !['network_id','daemon_node_id','node_id','revision','activation','keys'].includes(k))
|
|
97
|
+
|| snapshot.network_id !== r.network_id || snapshot.daemon_node_id !== null || snapshot.node_id !== r.node_id
|
|
98
|
+
|| !Number.isSafeInteger(snapshot.revision) || snapshot.revision < 0 || snapshot.activation !== 'next_start'
|
|
99
|
+
|| !Array.isArray(snapshot.keys) || snapshot.keys.length > 128 || new Set(snapshot.keys.map((x:any)=>x?.key)).size !== snapshot.keys.length
|
|
100
|
+
|| snapshot.keys.some((x:any)=>!x || Object.keys(x).some(k=>!['key','source'].includes(k)) || !validScopedSecretKey(x.key) || x.source !== 'node')
|
|
101
|
+
|| (r.action !== 'list' && snapshot.revision !== r.revision! + 1)
|
|
102
|
+
|| (r.action === 'put' && !snapshot.keys.some((x:any)=>x.key === r.key))
|
|
103
|
+
|| (r.action === 'delete' && snapshot.keys.some((x:any)=>x.key === r.key))) return denied('invalid_secret_receipt');
|
|
104
|
+
r.snapshot = snapshot;
|
|
105
|
+
}
|
|
106
|
+
r.status = failed ? 'failed' : 'succeeded'; if (failed) r.error = 'secret_operation_unavailable'; delete r.value;
|
|
107
|
+
return { ok: true, status: r.status };
|
|
108
|
+
}
|
|
109
|
+
export function requestScopedSecrets(h: Human, daemon: string, node: string | null, action: Request['action'], key?: string, value?: string, revision?: number) {
|
|
110
|
+
const refusal = authorize(h); if (refusal) return refusal;
|
|
111
|
+
if (!daemonSupported(h.networkId!, daemon)) return denied('scoped_secrets_upgrade_required');
|
|
112
|
+
if (node !== null && !providerScanTargets(h.networkId!, daemon).some(t => t.node_id === node)) return denied('secret_target_not_bound');
|
|
113
|
+
if (action !== 'list' && (!validScopedSecretKey(key)
|
|
114
|
+
|| !Number.isSafeInteger(revision) || revision! < 0 || (action === 'put' && (typeof value !== 'string' || !value || Buffer.byteLength(value) > 8192 || value.includes('\0'))))) return denied('invalid_secret_input');
|
|
115
|
+
expire();
|
|
116
|
+
// #1510 — same observation on the daemon lane (the daemon applies the value).
|
|
117
|
+
if (action === 'put') {
|
|
118
|
+
const transport = transportOf(h.networkId!, daemon);
|
|
119
|
+
const verdict = secretTransportVerdict(transport);
|
|
120
|
+
if (verdict) return denied(verdict);
|
|
121
|
+
observeSecretWrite(h.networkId!, daemon, `secret_${action}`);
|
|
122
|
+
}
|
|
123
|
+
if ([...requests.values()].some(r => r.network_id === h.networkId && r.daemon_node_id === daemon && r.status === 'pending')) return denied('secret_store_busy');
|
|
124
|
+
if (requests.size >= 1000) return denied('secret_queue_busy');
|
|
125
|
+
const r: Request = { request_id: `dsk_${randomUUID()}`, network_id: h.networkId!, daemon_node_id: daemon,
|
|
126
|
+
node_id: node, action, ...(action === 'list' ? {} : { key, revision, ...(action === 'put' ? { value } : {}) }),
|
|
127
|
+
expires_at: Date.now() + 120_000, status: 'pending' };
|
|
128
|
+
requests.set(r.request_id, r);
|
|
129
|
+
return { ok: true as const, request_id: r.request_id, status: r.status, expires_at: r.expires_at };
|
|
130
|
+
}
|
|
131
|
+
export function getScopedSecrets(h: Human, id: string) {
|
|
132
|
+
const refusal = authorize(h); if (refusal) return refusal; expire();
|
|
133
|
+
const r = requests.get(id);
|
|
134
|
+
if (!r || r.network_id !== h.networkId) return denied('request_not_found');
|
|
135
|
+
return { ok: true as const, request_id: id, daemon_node_id: r.daemon_node_id, node_id: r.node_id,
|
|
136
|
+
status: r.status, ...(r.snapshot ? { snapshot: r.snapshot } : {}), ...(r.error ? { error: r.error } : {}) };
|
|
137
|
+
}
|
|
138
|
+
export function pullScopedSecrets(d: Daemon) {
|
|
139
|
+
if (!d.ok || !daemonSupported(d.networkId, d.daemonNodeId)) return denied('caller_not_a_daemon'); expire();
|
|
140
|
+
const targets = providerScanTargets(d.networkId, d.daemonNodeId);
|
|
141
|
+
return { ok: true, requests: [...requests.values()].filter(r => r.network_id === d.networkId && r.daemon_node_id === d.daemonNodeId && r.status === 'pending')
|
|
142
|
+
.flatMap(r => {
|
|
143
|
+
if (r.node_id !== null && !targets.some(t => t.node_id === r.node_id)) { r.status = 'failed'; r.error = 'secret_target_not_bound'; delete r.value; return []; }
|
|
144
|
+
const { status, snapshot, error, ...input } = r;
|
|
145
|
+
return [{ ...input, targets }];
|
|
146
|
+
}) };
|
|
147
|
+
}
|
|
148
|
+
export function ackScopedSecrets(d: Daemon, id: string, snapshot: any, failed = false) {
|
|
149
|
+
if (!d.ok || !daemonSupported(d.networkId, d.daemonNodeId)) return denied('caller_not_a_daemon'); expire();
|
|
150
|
+
const r = requests.get(id);
|
|
151
|
+
if (!r || r.network_id !== d.networkId || r.daemon_node_id !== d.daemonNodeId) return denied('request_not_found');
|
|
152
|
+
if (r.status !== 'pending') return { ok: r.status === 'succeeded' || r.status === 'failed', status: r.status };
|
|
153
|
+
if (!failed) {
|
|
154
|
+
if (!snapshot || Object.keys(snapshot).some(k => !['network_id','daemon_node_id','node_id','revision','activation','keys'].includes(k))
|
|
155
|
+
|| snapshot.network_id !== r.network_id || snapshot.daemon_node_id !== r.daemon_node_id || snapshot.node_id !== r.node_id
|
|
156
|
+
|| !Number.isSafeInteger(snapshot.revision) || snapshot.revision < 0 || snapshot.activation !== 'next_start'
|
|
157
|
+
|| !Array.isArray(snapshot.keys) || snapshot.keys.length > 256 || new Set(snapshot.keys.map((x:any)=>x.key)).size !== snapshot.keys.length
|
|
158
|
+
|| snapshot.keys.some((x:any) => !x || Object.keys(x).some(k=>!['key','source'].includes(k)) || !validScopedSecretKey(x.key)
|
|
159
|
+
|| !['daemon','node'].includes(x.source) || (r.node_id === null && x.source !== 'daemon'))
|
|
160
|
+
|| (r.action !== 'list' && snapshot.revision !== r.revision! + 1)
|
|
161
|
+
|| (r.action === 'put' && !snapshot.keys.some((x:any)=>x.key === r.key && x.source === (r.node_id ? 'node' : 'daemon')))) return denied('invalid_secret_receipt');
|
|
162
|
+
if (r.node_id !== null && !providerScanTargets(r.network_id,r.daemon_node_id).some(t=>t.node_id === r.node_id)) return denied('secret_target_not_bound');
|
|
163
|
+
r.snapshot = snapshot;
|
|
164
|
+
}
|
|
165
|
+
r.status = failed ? 'failed' : 'succeeded'; if (failed) r.error = 'secret_operation_unavailable'; delete r.value;
|
|
166
|
+
return { ok: true, status: r.status };
|
|
167
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// #2149 的负控:**注入一个假秘密,断言它不出现在任何响应里**。
|
|
2
|
+
//
|
|
3
|
+
// 起因(#2149):TMA云鲸对 CommHub MCP 做只读扫描时收到 502,而**代理**生成的非 JSON 错误页
|
|
4
|
+
// 把本次请求的鉴权相关请求头回显在了正文里。那张卡的动作 2 是「修代理」,动作 3 是
|
|
5
|
+
// 「用注入的假秘密做负控:构造 502/超时/上游断开,断言响应与日志均无原值」。
|
|
6
|
+
//
|
|
7
|
+
// 代理不在本仓,但**本仓自己能承诺的那一半**同样需要负控:hub 自己的每一条错误路径
|
|
8
|
+
// 都不能回显 Authorization / 请求体里的口令。没有这条负控时,「我们没写这种代码」
|
|
9
|
+
// 与「我们写了但没人试过」在报告上同形。
|
|
10
|
+
//
|
|
11
|
+
// 判据:假秘密带随机后缀 ⇒ 一次真调用后,响应体、响应头、以及本进程的 stderr 都不含它。
|
|
12
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
13
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { register } from "./auth.js";
|
|
17
|
+
|
|
18
|
+
const DIR = mkdtempSync(join(tmpdir(), "anet-secret-echo-"));
|
|
19
|
+
const STAMP = () => `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 10)}`;
|
|
20
|
+
let BASE = "";
|
|
21
|
+
let hub: any = null;
|
|
22
|
+
let USER = "";
|
|
23
|
+
const PW = "SecretEchoPassw0rd!x";
|
|
24
|
+
|
|
25
|
+
/** 每个用例自己造一个秘密:带随机后缀,确保它不可能「碰巧」出现在任何固定文案里。 */
|
|
26
|
+
const secret = () => `sk-ECHO-${STAMP()}`;
|
|
27
|
+
|
|
28
|
+
type Reply = { status: number; text: string; headers: string[] };
|
|
29
|
+
|
|
30
|
+
async function raw(path: string, init: RequestInit = {}): Promise<Reply> {
|
|
31
|
+
const res = await fetch(`${BASE}${path}`, init);
|
|
32
|
+
const text = await res.text();
|
|
33
|
+
return { status: res.status, text, headers: [...res.headers].map(([k, v]) => `${k}: ${v}`) };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function assertNoEcho(reply: Reply, needle: string, label: string) {
|
|
37
|
+
const where: string[] = [];
|
|
38
|
+
if (reply.text.includes(needle)) where.push("body");
|
|
39
|
+
if (reply.headers.join("\n").includes(needle)) where.push("headers");
|
|
40
|
+
expect({ label, leakedIn: where }).toEqual({ label, leakedIn: [] });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
beforeAll(async () => {
|
|
44
|
+
process.env.COMMHUB_DB ||= join(DIR, "hub.db");
|
|
45
|
+
process.env.COMMHUB_UPLOADS_DIR = join(DIR, "uploads");
|
|
46
|
+
process.env.HOST = "127.0.0.1";
|
|
47
|
+
process.env.COMMHUB_LOGIN_IP_MAX = "1000";
|
|
48
|
+
USER = `echo_user_${Date.now()}`;
|
|
49
|
+
register(USER, PW);
|
|
50
|
+
const mod: any = await import("./server.js");
|
|
51
|
+
hub = mod.bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
52
|
+
BASE = `http://127.0.0.1:${hub.port}`;
|
|
53
|
+
}, 30_000);
|
|
54
|
+
|
|
55
|
+
afterAll(() => {
|
|
56
|
+
try { hub?.stop?.(true); } catch {}
|
|
57
|
+
try { rmSync(DIR, { recursive: true, force: true }); } catch {}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("#2149 负控:注入的假秘密不得被回显", () => {
|
|
61
|
+
test("无效 Bearer token ⇒ 401 的回显里没有 token 原值", async () => {
|
|
62
|
+
const s = secret();
|
|
63
|
+
const r = await raw("/api/status", { headers: { Authorization: `Bearer ${s}` } });
|
|
64
|
+
expect(r.status).toBe(401);
|
|
65
|
+
assertNoEcho(r, s, "invalid bearer");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("无效 token 打 MCP ⇒ 错误信封里没有 token 原值", async () => {
|
|
69
|
+
const s = secret();
|
|
70
|
+
const r = await raw("/mcp", {
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: { Authorization: `Bearer ${s}`, "Content-Type": "application/json", Accept: "application/json, text/event-stream" },
|
|
73
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list", params: {} }),
|
|
74
|
+
});
|
|
75
|
+
expect(r.status).toBeGreaterThanOrEqual(400);
|
|
76
|
+
assertNoEcho(r, s, "mcp invalid bearer");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("坏 JSON 请求体里塞秘密 ⇒ 400 的回显里没有正文原值", async () => {
|
|
80
|
+
const s = secret();
|
|
81
|
+
const r = await raw("/api/auth/login", {
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: { "Content-Type": "application/json" },
|
|
84
|
+
body: `{"username":"${USER}","password":"${s}",`, // 故意截断
|
|
85
|
+
});
|
|
86
|
+
expect(r.status).toBe(400);
|
|
87
|
+
assertNoEcho(r, s, "malformed json body");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("口令错误的登录 ⇒ 401 的回显里没有口令原值", async () => {
|
|
91
|
+
const s = secret();
|
|
92
|
+
const r = await raw("/api/auth/login", {
|
|
93
|
+
method: "POST",
|
|
94
|
+
headers: { "Content-Type": "application/json" },
|
|
95
|
+
body: JSON.stringify({ username: USER, password: s }),
|
|
96
|
+
});
|
|
97
|
+
expect(r.status).toBe(401);
|
|
98
|
+
assertNoEcho(r, s, "wrong password");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("未知路由 + 无效 token ⇒ 先 401(鉴权在路由匹配之前),回显里没有 token 原值", async () => {
|
|
102
|
+
// 实测:这里拿到的是 **401 而不是 404** —— 鉴权在路由匹配之前。
|
|
103
|
+
// 顺带说明一件事(值得记):无凭证的调用方无法通过状态码区分「路由不存在」与「路由存在但要鉴权」,
|
|
104
|
+
// 这是**探测面变小**,不是缺陷。所以我不断言 404,只断言「不许回显」。
|
|
105
|
+
const s = secret();
|
|
106
|
+
const r = await raw("/api/definitely-not-a-route", { headers: { Authorization: `Bearer ${s}` } });
|
|
107
|
+
expect(r.status).toBe(401);
|
|
108
|
+
assertNoEcho(r, s, "unknown route");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("节点令牌打需要 user token 的端点 ⇒ 403 的回显里没有令牌原值", async () => {
|
|
112
|
+
// 这条覆盖的是「鉴权投影」这一层:拒绝消息会不会把调用方凭证带出来。
|
|
113
|
+
const s = secret();
|
|
114
|
+
const r = await raw("/api/providers", { headers: { Authorization: `Bearer ${s}` } });
|
|
115
|
+
expect([401, 403]).toContain(r.status);
|
|
116
|
+
assertNoEcho(r, s, "user-token-only endpoint");
|
|
117
|
+
});
|
|
118
|
+
});
|