@sleep2agi/commhub-server 0.9.0-preview.24 → 0.9.0-preview.240
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 +129 -9
- package/bin/commhub.ts +93 -9
- package/package.json +7 -7
- package/src/ack-create-request-transport.test.ts +182 -0
- package/src/ack-create-request.test.ts +50 -7
- package/src/admin-delete-network-http.test.ts +228 -0
- package/src/admin-networks-http.test.ts +88 -0
- package/src/adoption-candidates-http.test.ts +137 -0
- package/src/adoption-candidates.ts +158 -0
- package/src/agent-access-batch.test.ts +210 -0
- package/src/agent-access.ts +487 -0
- package/src/agent-acl-groups-http.test.ts +247 -0
- package/src/agent-acl-http.test.ts +659 -0
- package/src/agent-acl-slice3-http.test.ts +654 -0
- package/src/agent-department-http.test.ts +215 -0
- package/src/agent-groups-perf.test.ts +223 -0
- package/src/agent-notice.ts +48 -0
- package/src/agent-team-whoami-http.test.ts +98 -0
- package/src/agent-teams-http.test.ts +330 -0
- package/src/agent-teams.ts +244 -0
- package/src/alias-baseline-2571.test.ts +162 -0
- package/src/alias-baseline.ts +113 -0
- package/src/alias-filter.test.ts +72 -0
- package/src/alias-filter.ts +42 -0
- package/src/api-host-supervisors-can-create-nodes.test.ts +350 -0
- package/src/api-host-supervisors-fallback.test.ts +6 -7
- package/src/api-host-supervisors-runtime-readiness.test.ts +195 -0
- package/src/api-nodes-shape.test.ts +95 -4
- package/src/auth-password-change-cli-tokens-http.test.ts +423 -0
- package/src/auth-sessions-http.test.ts +250 -0
- package/src/auth-validate.test.ts +5 -1
- package/src/auth-weak-password-login.test.ts +176 -0
- package/src/auth.ts +609 -51
- package/src/avatar-validate.test.ts +52 -2
- package/src/avatar-validate.ts +35 -1
- package/src/backfill-node-ids-2664.test.ts +128 -0
- package/src/binding-generation-http.test.ts +121 -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/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 +248 -0
- package/src/clone-node.ts +289 -0
- package/src/codex-config-flags.ts +77 -0
- package/src/codex-fork-contract.ts +23 -0
- package/src/codex-fork-migration.test.ts +38 -0
- package/src/commhub-bin-args.test.ts +85 -0
- package/src/config-apply-validate.test.ts +188 -1
- package/src/config-apply-validate.ts +222 -3
- package/src/cors-origins.test.ts +73 -0
- package/src/create-node-blocked-gate.test.ts +356 -0
- package/src/create-node-network-id.test.ts +91 -0
- package/src/create-node-tool-schema.test.ts +49 -0
- package/src/create-node-unicode-name.test.ts +120 -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 +289 -0
- package/src/create-node.ts +88 -23
- package/src/daemon-provider-snapshots.test.ts +434 -0
- package/src/daemon-provider-snapshots.ts +327 -0
- package/src/daemon-token-owner-http.test.ts +236 -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 +1264 -153
- package/src/delivered-without-push.test.ts +140 -0
- package/src/department-groups-http.test.ts +209 -0
- package/src/department-groups-sync-http.test.ts +328 -0
- package/src/department-groups.ts +434 -0
- package/src/department-heads-http.test.ts +350 -0
- package/src/department-heads.ts +226 -0
- package/src/departments-agent-count.test.ts +132 -0
- package/src/departments-http.test.ts +185 -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 +178 -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/ext-token-shared.test.ts +60 -0
- package/src/ext-validation-regression.test.ts +131 -0
- 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 +73 -18
- package/src/file-download-date-bucket.test.ts +436 -0
- package/src/file-network-scope-dev-open.test.ts +97 -0
- package/src/file-network-scope.test.ts +732 -0
- package/src/group-membership-events-http.test.ts +264 -0
- package/src/group-messages-http.test.ts +482 -0
- package/src/group-messages.ts +297 -0
- package/src/health-anon-readers.ts +60 -0
- package/src/health-host-disk-2756.test.ts +71 -0
- package/src/health-redaction.test.ts +1443 -3
- 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 +564 -0
- package/src/hub-provider-config.test.ts +156 -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 +310 -0
- package/src/inbox-count.ts +29 -0
- package/src/index.ts +6 -2
- package/src/license-state.test.ts +56 -0
- package/src/license-state.ts +48 -0
- package/src/list-host-supervisors.test.ts +15 -4
- 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 +165 -0
- package/src/mcp-route-label-http.test.ts +120 -0
- package/src/mcp-write-network-resolution.test.ts +435 -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-rules-http.test.ts +169 -0
- package/src/network-rules.ts +129 -0
- package/src/network-scope.ts +276 -0
- package/src/network-token-membership-http.test.ts +139 -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 +1091 -0
- package/src/node-create-request-status-http.test.ts +105 -0
- package/src/node-daemon-bindings.test.ts +132 -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 +344 -0
- package/src/node-health-codex-login.test.ts +120 -0
- package/src/node-health-dispatch-http.test.ts +335 -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 +250 -0
- package/src/node-lifecycle-read.ts +124 -0
- package/src/node-logs-transport.test.ts +263 -0
- package/src/node-peer-allowlist.test.ts +114 -0
- package/src/node-permissions-http.test.ts +728 -0
- package/src/node-permissions.ts +494 -0
- package/src/node-request-retention.test.ts +281 -0
- package/src/node-request-retention.ts +120 -0
- package/src/node-secret-rest-http.test.ts +190 -0
- package/src/node-serviceability.test.ts +86 -0
- package/src/node-serviceability.ts +124 -0
- package/src/node-session-control-http.test.ts +310 -0
- package/src/node-session-control.ts +258 -0
- package/src/node-skills-transport.test.ts +212 -0
- package/src/node-token-identity.ts +35 -0
- package/src/node-token-ownership.ts +51 -0
- package/src/node-token-privilege-http.test.ts +158 -0
- package/src/not-found-api-http.test.ts +67 -0
- package/src/observer-avatar-http.test.ts +102 -9
- package/src/observer-push.test.ts +76 -0
- package/src/opencode-catalog-report-http.test.ts +139 -0
- package/src/opencode-v2-catalog.test.ts +268 -0
- package/src/opencode-v2-catalog.ts +356 -0
- package/src/package-version-consistency.test.ts +25 -0
- package/src/parent-source-marker.test.ts +50 -0
- package/src/password-network-tokens.ts +25 -0
- package/src/peer-reply-atomic.test.ts +457 -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/project-dir-warn-clear-http.test.ts +132 -0
- package/src/project-viewer-can-http.test.ts +116 -0
- package/src/push.test.ts +20 -10
- package/src/push.ts +373 -9
- package/src/redact-tokens.test.ts +86 -0
- package/src/redact-tokens.ts +43 -0
- package/src/rejection-counters.test.ts +72 -0
- package/src/rejection-counters.ts +173 -0
- package/src/rename.ts +38 -10
- package/src/reply-target-derivation.test.ts +96 -0
- package/src/report-status-handover-capabilities-http.test.ts +124 -0
- package/src/report-status-host-schema.test.ts +235 -0
- package/src/report-status-resume-id-handover.test.ts +184 -0
- package/src/report-status-secret-keys.test.ts +140 -0
- package/src/require-explicit-test-db.ts +9 -0
- package/src/requirement-due-reminders-http.test.ts +620 -0
- package/src/requirement-due-reminders.ts +416 -0
- package/src/requirement-events-http.test.ts +295 -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 +309 -0
- package/src/requirement-tag-ops-http.test.ts +443 -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 +112 -0
- package/src/requirements-comment-http.test.ts +167 -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 +163 -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 +2116 -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 +237 -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 +432 -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 +193 -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 +279 -0
- package/src/scheduled-requirement-wake.ts +125 -0
- package/src/scheduled-run-terminal.test.ts +268 -0
- package/src/scheduled-skip-blocking-task.test.ts +120 -0
- package/src/scheduled-skip-path-backoff-2622.test.ts +98 -0
- package/src/scheduled-stuck-http.test.ts +316 -0
- package/src/scheduled-stuck-notice-cap.test.ts +80 -0
- package/src/scheduled-stuck.ts +219 -0
- package/src/scheduled-tasks-http.test.ts +679 -0
- package/src/scheduled-tasks.ts +959 -0
- package/src/scheduled-work-outcome-http.test.ts +154 -0
- package/src/scheduled-work-outcome.ts +50 -0
- package/src/scoped-secrets.ts +141 -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 +458 -0
- 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 +5010 -429
- 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 +142 -0
- package/src/sqlite-close-checkpoint.test.ts +78 -0
- package/src/start-node.test.ts +264 -0
- package/src/status-alias-filter-http.test.ts +106 -0
- package/src/status-alias-resolver-http.test.ts +163 -0
- package/src/status-alias-resolver.ts +19 -0
- package/src/status-node-id-filter-http.test.ts +161 -0
- package/src/status-read-cache-http.test.ts +229 -0
- package/src/status-read-cache.ts +129 -0
- package/src/stop-delete-node.test.ts +567 -1
- package/src/task-access-http.test.ts +402 -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 +490 -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 +287 -0
- package/src/task-expiry-notice.ts +315 -0
- package/src/task-idempotency-mcp.test.ts +142 -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 +204 -0
- package/src/task-lifecycle-watcher.ts +109 -0
- package/src/task-network-resolution-http.test.ts +140 -0
- package/src/task-offline-delivery-2668.test.ts +119 -0
- package/src/task-offline-delivery.ts +81 -0
- package/src/task-orphan-http.test.ts +287 -0
- package/src/task-orphan.ts +119 -0
- package/src/task-queue-ahead-http.test.ts +309 -0
- package/src/task-queue-ahead-scale.test.ts +236 -0
- package/src/task-queue-ahead.ts +186 -0
- package/src/task-rejection-log-http.test.ts +160 -0
- package/src/task-rejection-log.ts +61 -0
- package/src/task-sender-http.test.ts +143 -0
- package/src/task-stale-open-http.test.ts +292 -0
- package/src/task-stale-open.ts +103 -0
- package/src/tasks-pagination-http.test.ts +141 -0
- package/src/team-rules-status-http.test.ts +90 -0
- package/src/team-rules-status.test.ts +59 -0
- package/src/team-rules-status.ts +72 -0
- package/src/tmux-allowlist.test.ts +48 -0
- package/src/tool-audience-http.test.ts +230 -0
- package/src/tool-audience.ts +127 -0
- package/src/tools-list-json-schema.test.ts +94 -0
- package/src/tools.ts +4310 -419
- package/src/upload-early-reject-guard.test.ts +155 -0
- package/src/uploads-http.test.ts +86 -7
- package/src/uploads.ts +103 -6
- 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 +348 -0
- package/src/user-inbox-by-agent-http.test.ts +161 -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,85 @@
|
|
|
1
|
+
import { afterAll, describe, expect, test } from "bun:test";
|
|
2
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
// commhub-server must refuse what it does not understand instead of starting a
|
|
8
|
+
// Hub on the defaults (the live ~/.commhub/commhub.db). Every child gets a
|
|
9
|
+
// throwaway HOME and a throwaway PORT, so even a regression binds nothing real.
|
|
10
|
+
const BIN = join(dirname(fileURLToPath(import.meta.url)), "..", "bin", "commhub.ts");
|
|
11
|
+
const PKG_VERSION = JSON.parse(readFileSync(join(dirname(BIN), "..", "package.json"), "utf8")).version as string;
|
|
12
|
+
const home = mkdtempSync(join(tmpdir(), "anet-bin-args-"));
|
|
13
|
+
const PORT = String(26000 + Math.floor(Math.random() * 3000));
|
|
14
|
+
|
|
15
|
+
afterAll(() => rmSync(home, { recursive: true, force: true }));
|
|
16
|
+
|
|
17
|
+
function run(args: string[], extraEnv: Record<string, string> = {}, timeoutMs = 15_000) {
|
|
18
|
+
const proc = Bun.spawnSync(["bun", BIN, ...args], {
|
|
19
|
+
env: { PATH: process.env.PATH ?? "", HOME: home, PORT, HOST: "127.0.0.1", ...extraEnv },
|
|
20
|
+
stdout: "pipe", stderr: "pipe", timeout: timeoutMs,
|
|
21
|
+
});
|
|
22
|
+
return { code: proc.exitCode, stdout: proc.stdout.toString(), stderr: proc.stderr.toString() };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function listening(port: string): Promise<boolean> {
|
|
26
|
+
try { await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(500) }); return true; } catch { return false; }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe("commhub-server argument handling", () => {
|
|
30
|
+
for (const [args, message] of [
|
|
31
|
+
[["bogus"], "unknown command bogus"],
|
|
32
|
+
[["--port=29999"], "unknown option --port=29999"],
|
|
33
|
+
[["--bogus-flag"], "unknown option --bogus-flag"],
|
|
34
|
+
[["--port"], "--port needs a value"],
|
|
35
|
+
[["--db", "--dev-open"], "--db needs a value"],
|
|
36
|
+
] as const) {
|
|
37
|
+
test(`${args.join(" ")} → exit 2, no database, nothing listening`, async () => {
|
|
38
|
+
const r = run([...args]);
|
|
39
|
+
expect(r.code).toBe(2);
|
|
40
|
+
expect(r.stderr).toContain(message);
|
|
41
|
+
expect(r.stderr).toContain("commhub-server --help");
|
|
42
|
+
expect(existsSync(join(home, ".commhub"))).toBe(false);
|
|
43
|
+
expect(await listening(PORT)).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
test("migrate-to-pg with missing or unknown arguments exits 2 and starts nothing", async () => {
|
|
48
|
+
const missing = run(["migrate-to-pg", "--from", "/x.db"]);
|
|
49
|
+
expect(missing.code).toBe(2);
|
|
50
|
+
expect(missing.stdout).toContain("commhub-server migrate-to-pg --from <sqlite file> --to <postgres url>");
|
|
51
|
+
const unknown = run(["migrate-to-pg", "--from", "/x.db", "--to", "postgres://u@127.0.0.1/anet_x_test", "--bogus"]);
|
|
52
|
+
expect(unknown.code).toBe(2);
|
|
53
|
+
expect(unknown.stderr).toContain("unknown argument --bogus");
|
|
54
|
+
expect(existsSync(join(home, ".commhub"))).toBe(false);
|
|
55
|
+
expect(await listening(PORT)).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("--help and --version exit 0 without starting", async () => {
|
|
59
|
+
const help = run(["--help"]);
|
|
60
|
+
expect(help.code).toBe(0);
|
|
61
|
+
expect(help.stdout).toContain("--port, -p <port>");
|
|
62
|
+
const version = run(["--version"]);
|
|
63
|
+
expect(version.code).toBe(0);
|
|
64
|
+
expect(version.stdout.trim()).toBe(PKG_VERSION);
|
|
65
|
+
expect(existsSync(join(home, ".commhub"))).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("the known forms still start a Hub", async () => {
|
|
69
|
+
const db = join(home, "known.db");
|
|
70
|
+
const port = String(Number(PORT) + 1);
|
|
71
|
+
const child = Bun.spawn(["bun", BIN, "--port", port, "--host", "127.0.0.1", "--db", db, "--dev-open"], {
|
|
72
|
+
env: { PATH: process.env.PATH ?? "", HOME: home }, stdout: "pipe", stderr: "pipe",
|
|
73
|
+
});
|
|
74
|
+
try {
|
|
75
|
+
let up = false;
|
|
76
|
+
for (let i = 0; i < 100 && !up; i++) { up = await listening(port); if (!up) await Bun.sleep(100); }
|
|
77
|
+
expect(up).toBe(true);
|
|
78
|
+
expect(existsSync(db)).toBe(true);
|
|
79
|
+
expect(existsSync(join(home, ".commhub", "commhub.db"))).toBe(false);
|
|
80
|
+
} finally {
|
|
81
|
+
child.kill();
|
|
82
|
+
await child.exited;
|
|
83
|
+
}
|
|
84
|
+
}, 30_000);
|
|
85
|
+
});
|
|
@@ -12,6 +12,10 @@ import {
|
|
|
12
12
|
EDITABLE_CHANNELS,
|
|
13
13
|
isAllowedToChangeFlag,
|
|
14
14
|
computeApplyMode,
|
|
15
|
+
readOpencodeSnapshotFlags,
|
|
16
|
+
readConfigUpdateCapable,
|
|
17
|
+
configUpdateCapabilityDivergence,
|
|
18
|
+
readSystemdSupervision,
|
|
15
19
|
validatePatch,
|
|
16
20
|
narrowChannelsPatch,
|
|
17
21
|
} from "./config-apply-validate";
|
|
@@ -26,20 +30,28 @@ describe("ALLOWED_FLAGS — exact contract (no silent extension)", () => {
|
|
|
26
30
|
// the BLOCKER 2 schema-mismatch issue. P2 to add a claude-code-cli
|
|
27
31
|
// config-apply path.
|
|
28
32
|
expect([...ALLOWED_FLAGS].sort()).toEqual([
|
|
33
|
+
"approvalPolicy",
|
|
29
34
|
"budget",
|
|
35
|
+
"copresenceFullAccess",
|
|
30
36
|
"dangerouslySkipPermissions",
|
|
31
37
|
"maxTurns",
|
|
38
|
+
"modelReasoningEffort",
|
|
32
39
|
"permissionMode",
|
|
40
|
+
"sandboxMode",
|
|
41
|
+
"skipGitRepoCheck",
|
|
33
42
|
"timeout",
|
|
34
43
|
]);
|
|
35
44
|
});
|
|
36
45
|
});
|
|
37
46
|
|
|
38
47
|
describe("SECURITY_SENSITIVE_FLAGS — privilege-elevation surface", () => {
|
|
39
|
-
test("contains
|
|
48
|
+
test("contains privilege-elevation flags (teammateMode dropped — see ALLOWED_FLAGS comment)", () => {
|
|
40
49
|
expect([...SECURITY_SENSITIVE_FLAGS].sort()).toEqual([
|
|
50
|
+
"approvalPolicy",
|
|
51
|
+
"copresenceFullAccess",
|
|
41
52
|
"dangerouslySkipPermissions",
|
|
42
53
|
"permissionMode",
|
|
54
|
+
"sandboxMode",
|
|
43
55
|
]);
|
|
44
56
|
});
|
|
45
57
|
|
|
@@ -161,6 +173,10 @@ describe("computeApplyMode — tier classifier (RFC-024 §4)", () => {
|
|
|
161
173
|
expect(computeApplyMode("gpt-5", { maxTurns: 50 })).toBe("restart");
|
|
162
174
|
});
|
|
163
175
|
|
|
176
|
+
test("modelReasoningEffort flag alone → restart tier", () => {
|
|
177
|
+
expect(computeApplyMode(undefined, { modelReasoningEffort: "medium" })).toBe("restart");
|
|
178
|
+
});
|
|
179
|
+
|
|
164
180
|
test("mixed (only hot flags) → hot", () => {
|
|
165
181
|
expect(computeApplyMode(undefined, { maxTurns: 50, budget: 100 })).toBe("hot");
|
|
166
182
|
});
|
|
@@ -170,6 +186,67 @@ describe("computeApplyMode — tier classifier (RFC-024 §4)", () => {
|
|
|
170
186
|
});
|
|
171
187
|
});
|
|
172
188
|
|
|
189
|
+
// #3146 —— 客户端「切模型不必重启」。agent-node 从 OpenCode V2 共存起就能
|
|
190
|
+
// 在运行中的 TUI 会话里换模型,但 hub 把所有 `model` patch 一律判成
|
|
191
|
+
// restart,于是客户端显示「重启中」而节点永远不会重启。
|
|
192
|
+
describe("computeApplyMode — OpenCode V2 hot model switch (#3146)", () => {
|
|
193
|
+
const v2Copresence = {
|
|
194
|
+
runtime: "opencode-sdk",
|
|
195
|
+
opencodeGeneration: "v2" as const,
|
|
196
|
+
opencodeMode: "copresence",
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
test("model alone on an OpenCode V2 co-presence node → hot", () => {
|
|
200
|
+
expect(computeApplyMode("deepseek/deepseek-flash", {}, undefined, v2Copresence)).toBe("hot");
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test("runtime spelling aliases all resolve to hot (opencode-cli / opencode / opencode-sdk)", () => {
|
|
204
|
+
for (const runtime of ["opencode-sdk", "opencode-cli", "opencode"]) {
|
|
205
|
+
expect(computeApplyMode("m", {}, undefined, { ...v2Copresence, runtime })).toBe("hot");
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test("model alone without opts keeps the pre-#3146 restart answer", () => {
|
|
210
|
+
expect(computeApplyMode("deepseek/deepseek-flash", {})).toBe("restart");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("v1 node → restart (no live V2 session to switch)", () => {
|
|
214
|
+
expect(computeApplyMode("m", {}, undefined, { ...v2Copresence, opencodeGeneration: "v1" })).toBe("restart");
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("unknown generation → restart", () => {
|
|
218
|
+
expect(computeApplyMode("m", {}, undefined, { ...v2Copresence, opencodeGeneration: null })).toBe("restart");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("headless V2 node → restart (no co-presence session to drive)", () => {
|
|
222
|
+
expect(computeApplyMode("m", {}, undefined, { ...v2Copresence, opencodeMode: "headless" })).toBe("restart");
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test("non-OpenCode runtime → restart", () => {
|
|
226
|
+
expect(computeApplyMode("m", {}, undefined, { ...v2Copresence, runtime: "codex-app-server-sdk" })).toBe("restart");
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test("model + any flag → restart (mixed patch stays on the restart path)", () => {
|
|
230
|
+
expect(computeApplyMode("m", { maxTurns: 50 }, undefined, v2Copresence)).toBe("restart");
|
|
231
|
+
expect(computeApplyMode("m", { timeout: 60000 }, undefined, v2Copresence)).toBe("restart");
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test("model + channels → restart", () => {
|
|
235
|
+
expect(computeApplyMode("m", {}, ["feishu"], v2Copresence)).toBe("restart");
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test("readOpencodeSnapshotFlags parses text, object, and junk", () => {
|
|
239
|
+
expect(readOpencodeSnapshotFlags('{"flags":{"opencodeGeneration":"v2","opencodeMode":"copresence"}}'))
|
|
240
|
+
.toEqual({ opencodeGeneration: "v2", opencodeMode: "copresence" });
|
|
241
|
+
expect(readOpencodeSnapshotFlags({ flags: { opencodeGeneration: "v1" } }))
|
|
242
|
+
.toEqual({ opencodeGeneration: "v1", opencodeMode: null });
|
|
243
|
+
expect(readOpencodeSnapshotFlags("not json")).toEqual({ opencodeGeneration: null, opencodeMode: null });
|
|
244
|
+
expect(readOpencodeSnapshotFlags(null)).toEqual({ opencodeGeneration: null, opencodeMode: null });
|
|
245
|
+
expect(readOpencodeSnapshotFlags('{"flags":{"opencodeGeneration":"v9"}}'))
|
|
246
|
+
.toEqual({ opencodeGeneration: null, opencodeMode: null });
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
173
250
|
describe("validatePatch — model field", () => {
|
|
174
251
|
test("undefined model passes (no change)", () => {
|
|
175
252
|
expect(validatePatch(undefined, {})).toBeNull();
|
|
@@ -249,6 +326,15 @@ describe("validatePatch — per-flag enum / range", () => {
|
|
|
249
326
|
expect(validatePatch(undefined, { timeout: 3_600_001 })?.field).toBe("flags.timeout");
|
|
250
327
|
expect(validatePatch(undefined, { timeout: 60.5 })?.field).toBe("flags.timeout");
|
|
251
328
|
});
|
|
329
|
+
test("timeout: 0 = no limit; 1..999 is seconds-shaped and rejected (#605)", () => {
|
|
330
|
+
expect(validatePatch(undefined, { timeout: 0 })).toBeNull();
|
|
331
|
+
expect(validatePatch(undefined, { timeout: 1000 })).toBeNull();
|
|
332
|
+
for (const v of [1, 600, 999]) {
|
|
333
|
+
const r = validatePatch(undefined, { timeout: v });
|
|
334
|
+
expect(r?.field).toBe("flags.timeout");
|
|
335
|
+
expect(r?.reason).toContain("milliseconds");
|
|
336
|
+
}
|
|
337
|
+
});
|
|
252
338
|
});
|
|
253
339
|
|
|
254
340
|
describe("validatePatch — combinations", () => {
|
|
@@ -350,3 +436,104 @@ describe("validatePatch — channels defensive gate", () => {
|
|
|
350
436
|
expect(r?.field).toBe("channels");
|
|
351
437
|
});
|
|
352
438
|
});
|
|
439
|
+
|
|
440
|
+
describe("Codex config flags (#815)", () => {
|
|
441
|
+
test("yolo bundle on codex-app-server passes", () => {
|
|
442
|
+
expect(validatePatch(undefined, {
|
|
443
|
+
approvalPolicy: "never",
|
|
444
|
+
sandboxMode: "danger-full-access",
|
|
445
|
+
skipGitRepoCheck: true,
|
|
446
|
+
copresenceFullAccess: true,
|
|
447
|
+
modelReasoningEffort: "low",
|
|
448
|
+
}, undefined, "codex-app-server")).toBeNull();
|
|
449
|
+
});
|
|
450
|
+
test("modelReasoningEffort invalid enum rejected", () => {
|
|
451
|
+
expect(validatePatch(undefined, { modelReasoningEffort: "max" }, undefined, "codex-app-server")?.field)
|
|
452
|
+
.toBe("flags.modelReasoningEffort");
|
|
453
|
+
});
|
|
454
|
+
test("codex flags on claude runtime rejected", () => {
|
|
455
|
+
expect(validatePatch(undefined, { modelReasoningEffort: "low" }, undefined, "claude-agent-sdk")?.field)
|
|
456
|
+
.toBe("flags.modelReasoningEffort");
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// 裸起节点(无 supervisor)收到 restart-tier 变更会安静地死掉:
|
|
461
|
+
// 写配置 → ack restarting → exit 75 → 没人拉起 → 更新判 timeout,
|
|
462
|
+
// 而调用方只看到「超时」。这里锁住「把后果说在前面」的读法。
|
|
463
|
+
describe("readConfigUpdateCapable", () => {
|
|
464
|
+
test("true / false / absent / junk", () => {
|
|
465
|
+
expect(readConfigUpdateCapable('{"config_update_capable":true}')).toBe(true);
|
|
466
|
+
expect(readConfigUpdateCapable('{"config_update_capable":false}')).toBe(false);
|
|
467
|
+
expect(readConfigUpdateCapable('{"model":"x"}')).toBeNull();
|
|
468
|
+
expect(readConfigUpdateCapable("not json")).toBeNull();
|
|
469
|
+
expect(readConfigUpdateCapable(null)).toBeNull();
|
|
470
|
+
// 非布尔一律 unknown,不能当成 false —— 否则会给没上报的节点发警告
|
|
471
|
+
expect(readConfigUpdateCapable('{"config_update_capable":"false"}')).toBeNull();
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
describe("readConfigUpdateCapable — restart_supervised 优先", () => {
|
|
476
|
+
test("prefers the named key when both are present", () => {
|
|
477
|
+
expect(readConfigUpdateCapable('{"restart_supervised":true,"config_update_capable":false}')).toBe(true);
|
|
478
|
+
expect(readConfigUpdateCapable('{"restart_supervised":false,"config_update_capable":true}')).toBe(false);
|
|
479
|
+
});
|
|
480
|
+
test("falls back to the legacy key for old nodes", () => {
|
|
481
|
+
expect(readConfigUpdateCapable('{"config_update_capable":true}')).toBe(true);
|
|
482
|
+
});
|
|
483
|
+
test("non-boolean named value falls through to legacy, then unknown", () => {
|
|
484
|
+
expect(readConfigUpdateCapable('{"restart_supervised":"true","config_update_capable":false}')).toBe(false);
|
|
485
|
+
expect(readConfigUpdateCapable('{"restart_supervised":"true"}')).toBeNull();
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
// 2026-10-31 —— 「被遮住的值」必须能被看见。
|
|
490
|
+
// readConfigUpdateCapable 一旦选定 restart_supervised,config_update_capable 就再也读不到了;
|
|
491
|
+
// 而「两个一致」与「有一个被遮住了」在调用方看来完全一样 —— 这是隐式回退的通用形状。
|
|
492
|
+
describe("configUpdateCapabilityDivergence — 双写字段的分歧本身就是读数", () => {
|
|
493
|
+
test("reports both values when they disagree, in either direction", () => {
|
|
494
|
+
expect(configUpdateCapabilityDivergence('{"restart_supervised":true,"config_update_capable":false}'))
|
|
495
|
+
.toEqual({ named: true, legacy: false });
|
|
496
|
+
expect(configUpdateCapabilityDivergence('{"restart_supervised":false,"config_update_capable":true}'))
|
|
497
|
+
.toEqual({ named: false, legacy: true });
|
|
498
|
+
});
|
|
499
|
+
test("stays quiet when they agree — that is the documented normal case", () => {
|
|
500
|
+
expect(configUpdateCapabilityDivergence('{"restart_supervised":true,"config_update_capable":true}')).toBeNull();
|
|
501
|
+
expect(configUpdateCapabilityDivergence('{"restart_supervised":false,"config_update_capable":false}')).toBeNull();
|
|
502
|
+
});
|
|
503
|
+
test("no divergence to report when only one field is present or shapes are unusable", () => {
|
|
504
|
+
expect(configUpdateCapabilityDivergence('{"restart_supervised":true}')).toBeNull();
|
|
505
|
+
expect(configUpdateCapabilityDivergence('{"config_update_capable":true}')).toBeNull();
|
|
506
|
+
expect(configUpdateCapabilityDivergence('{"restart_supervised":"true","config_update_capable":false}')).toBeNull();
|
|
507
|
+
expect(configUpdateCapabilityDivergence("")).toBeNull();
|
|
508
|
+
expect(configUpdateCapabilityDivergence("not json")).toBeNull();
|
|
509
|
+
expect(configUpdateCapabilityDivergence(null)).toBeNull();
|
|
510
|
+
expect(configUpdateCapabilityDivergence(undefined)).toBeNull();
|
|
511
|
+
});
|
|
512
|
+
test("accepts an already-parsed object (nodes may hand us either form)", () => {
|
|
513
|
+
expect(configUpdateCapabilityDivergence({ restart_supervised: true, config_update_capable: false }))
|
|
514
|
+
.toEqual({ named: true, legacy: false });
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
// 2026-10-31 —— #3168:节点自报的三态托管判定。
|
|
520
|
+
// 「它说自己没人拉」与「它说有人拉」处置相反;而「不知道」两边都不能当。
|
|
521
|
+
describe("readSystemdSupervision", () => {
|
|
522
|
+
test("reads the three declared states verbatim", () => {
|
|
523
|
+
expect(readSystemdSupervision(JSON.stringify({ systemd_supervision: "supervised" }))).toBe("supervised");
|
|
524
|
+
expect(readSystemdSupervision('{"systemd_supervision":"not_supervised"}')).toBe("not_supervised");
|
|
525
|
+
expect(readSystemdSupervision({ systemd_supervision: "unknown" })).toBe("unknown");
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
test("missing field ⇒ null, which is NOT the same as unknown", () => {
|
|
529
|
+
// 缺失 = 这一版还不会报(老节点);unknown = 会报但这次判不出来。
|
|
530
|
+
expect(readSystemdSupervision('{"config_update_capable":false}')).toBeNull();
|
|
531
|
+
expect(readSystemdSupervision("")).toBeNull();
|
|
532
|
+
expect(readSystemdSupervision("not json")).toBeNull();
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
test("rejects values outside the declared set (a typo must not silently mean 'supervised')", () => {
|
|
536
|
+
expect(readSystemdSupervision('{"systemd_supervision":"yes"}')).toBeNull();
|
|
537
|
+
expect(readSystemdSupervision('{"systemd_supervision":true}')).toBeNull();
|
|
538
|
+
});
|
|
539
|
+
});
|
|
@@ -5,6 +5,15 @@
|
|
|
5
5
|
// tools.ts wrap these with auth checks (SEC-1 network scope, ntok_/utok_
|
|
6
6
|
// caller identity, role gates).
|
|
7
7
|
|
|
8
|
+
import { isValidTimeoutMs, TIMEOUT_MS_REASON } from "./create-node-validate.js";
|
|
9
|
+
import {
|
|
10
|
+
REASONING_EFFORT_VALUES,
|
|
11
|
+
validateCodexConfigFlag,
|
|
12
|
+
type ModelReasoningEffort,
|
|
13
|
+
} from "./codex-config-flags.js";
|
|
14
|
+
|
|
15
|
+
export { REASONING_EFFORT_VALUES, type ModelReasoningEffort } from "./codex-config-flags.js";
|
|
16
|
+
|
|
8
17
|
/**
|
|
9
18
|
* Fields the dashboard may change. Anything not in this list is rejected
|
|
10
19
|
* by hub-side validation regardless of role — the UI cannot smuggle
|
|
@@ -16,6 +25,12 @@ export const ALLOWED_FLAGS = new Set<string>([
|
|
|
16
25
|
"maxTurns",
|
|
17
26
|
"budget",
|
|
18
27
|
"timeout",
|
|
28
|
+
// Codex (#815 / client): posture + co-presence grant + thinking level
|
|
29
|
+
"approvalPolicy",
|
|
30
|
+
"sandboxMode",
|
|
31
|
+
"skipGitRepoCheck",
|
|
32
|
+
"copresenceFullAccess",
|
|
33
|
+
"modelReasoningEffort",
|
|
19
34
|
]);
|
|
20
35
|
// NB on teammateMode (dropped from P1 scope per #290 cross-agent
|
|
21
36
|
// review): teammateMode is consumed ONLY by the claude-code-cli
|
|
@@ -43,6 +58,9 @@ export const ALLOWED_FLAGS = new Set<string>([
|
|
|
43
58
|
export const SECURITY_SENSITIVE_FLAGS = new Set<string>([
|
|
44
59
|
"permissionMode",
|
|
45
60
|
"dangerouslySkipPermissions",
|
|
61
|
+
"approvalPolicy",
|
|
62
|
+
"sandboxMode",
|
|
63
|
+
"copresenceFullAccess",
|
|
46
64
|
]);
|
|
47
65
|
|
|
48
66
|
/**
|
|
@@ -55,6 +73,11 @@ export const RESTART_REQUIRED_FLAGS = new Set<string>([
|
|
|
55
73
|
"permissionMode",
|
|
56
74
|
"dangerouslySkipPermissions",
|
|
57
75
|
"timeout",
|
|
76
|
+
"approvalPolicy",
|
|
77
|
+
"sandboxMode",
|
|
78
|
+
"skipGitRepoCheck",
|
|
79
|
+
"copresenceFullAccess",
|
|
80
|
+
"modelReasoningEffort",
|
|
58
81
|
]);
|
|
59
82
|
|
|
60
83
|
/**
|
|
@@ -126,6 +149,178 @@ export function isAllowedToChangeFlag(
|
|
|
126
149
|
return null;
|
|
127
150
|
}
|
|
128
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Runtime families the hub treats as "OpenCode". `nodes.runtime` is
|
|
154
|
+
* written from report_status and carries the legacy `-sdk` bucket
|
|
155
|
+
* (`opencode-sdk`) for older CLI builds, while newer callers pass the
|
|
156
|
+
* config-level spelling (`opencode-cli` / `opencode`). All three mean
|
|
157
|
+
* the same agent-node runtime, so the hot-model-switch gate below must
|
|
158
|
+
* accept every spelling — otherwise the same node flips between hot
|
|
159
|
+
* and restart depending on which build reported last.
|
|
160
|
+
*/
|
|
161
|
+
const OPENCODE_RUNTIME_LABELS = new Set<string>(["opencode-sdk", "opencode-cli", "opencode"]);
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Read the OpenCode knobs the hub persists in `nodes.config_snapshot`.
|
|
165
|
+
* Both are reported by agent-node (see buildConfigSnapshot in
|
|
166
|
+
* agent-node/src/runtime/config-apply.ts) and are the only two fields
|
|
167
|
+
* the apply-mode decision needs.
|
|
168
|
+
*
|
|
169
|
+
* Snapshot is stored as text but older rows hold objects; a parse
|
|
170
|
+
* failure means "this cell is empty" (never an exception) — same
|
|
171
|
+
* fail-shape as the api-nodes projection.
|
|
172
|
+
*/
|
|
173
|
+
export function readOpencodeSnapshotFlags(configSnapshot: unknown): {
|
|
174
|
+
opencodeGeneration: "v1" | "v2" | null;
|
|
175
|
+
opencodeMode: string | null;
|
|
176
|
+
} {
|
|
177
|
+
let parsed: any = null;
|
|
178
|
+
try {
|
|
179
|
+
parsed = typeof configSnapshot === "string"
|
|
180
|
+
? (configSnapshot ? JSON.parse(configSnapshot) : null)
|
|
181
|
+
: configSnapshot;
|
|
182
|
+
} catch {
|
|
183
|
+
parsed = null;
|
|
184
|
+
}
|
|
185
|
+
const flags = parsed?.flags;
|
|
186
|
+
const generation = flags?.opencodeGeneration;
|
|
187
|
+
const mode = flags?.opencodeMode;
|
|
188
|
+
return {
|
|
189
|
+
opencodeGeneration: generation === "v1" || generation === "v2" ? generation : null,
|
|
190
|
+
opencodeMode: typeof mode === "string" && mode.length <= 32 ? mode : null,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* True when the node can swap the live model without a process restart.
|
|
196
|
+
*
|
|
197
|
+
* Mirrors `computeApplyMode` in agent-node/src/runtime/config-apply.ts
|
|
198
|
+
* (#3146). The node has been able to do this since OpenCode V2
|
|
199
|
+
* co-presence shipped, but the hub classified every `model` patch as
|
|
200
|
+
* `restart`, so the client showed "restarting" and waited for a
|
|
201
|
+
* restart that the node deliberately never performed. Hub and node now
|
|
202
|
+
* agree on the same three conditions:
|
|
203
|
+
*
|
|
204
|
+
* runtime ∈ OpenCode · opencodeGeneration === "v2" · mode === "copresence"
|
|
205
|
+
*
|
|
206
|
+
* `copresence` is required because the hot switch drives the running
|
|
207
|
+
* TUI session (`opencodeCopresenceSession.setSelectedModel`); a
|
|
208
|
+
* headless V2 node has no such session and must restart. Only a
|
|
209
|
+
* model-ONLY patch qualifies — adding flags or channels drags in
|
|
210
|
+
* restart-tier fields, and the node would restart anyway.
|
|
211
|
+
*/
|
|
212
|
+
export function isHotModelSwitchSupported(
|
|
213
|
+
model: string | undefined,
|
|
214
|
+
flags: Record<string, unknown>,
|
|
215
|
+
channels: string[] | undefined,
|
|
216
|
+
runtime: string | null | undefined,
|
|
217
|
+
opencodeGeneration: "v1" | "v2" | null,
|
|
218
|
+
opencodeMode: string | null,
|
|
219
|
+
): boolean {
|
|
220
|
+
if (model === undefined) return false;
|
|
221
|
+
if (Object.keys(flags).length !== 0) return false;
|
|
222
|
+
if (channels !== undefined) return false;
|
|
223
|
+
if (!runtime || !OPENCODE_RUNTIME_LABELS.has(runtime)) return false;
|
|
224
|
+
if (opencodeGeneration !== "v2") return false;
|
|
225
|
+
return opencodeMode === "copresence";
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Read `config_update_capable` from `nodes.config_snapshot`.
|
|
230
|
+
*
|
|
231
|
+
* agent-node reports this as "this process runs under a supervisor wrapper that
|
|
232
|
+
* honours the sentinel-75 restart path" (agent-node/src/cli.ts report_status).
|
|
233
|
+
* A bare-spawn node (`nohup node cli.js …`, no pm2/anet wrapper) reports
|
|
234
|
+
* `false` — and a restart-tier patch on such a node writes the config, acks
|
|
235
|
+
* `restarting`, exits 75, and **nothing respawns it**. The update then sits in
|
|
236
|
+
* `pending`/`restarting` until the 60s reaper marks it `timeout`, so the caller
|
|
237
|
+
* only ever sees "timed out" and never learns that the node is now down.
|
|
238
|
+
*
|
|
239
|
+
* Absent/unparseable snapshot → `null` ("unknown"), never `false`: we must not
|
|
240
|
+
* warn on nodes that simply haven't reported it yet.
|
|
241
|
+
*/
|
|
242
|
+
export function readConfigUpdateCapable(configSnapshot: unknown): boolean | null {
|
|
243
|
+
let parsed: any = null;
|
|
244
|
+
try {
|
|
245
|
+
parsed = typeof configSnapshot === "string"
|
|
246
|
+
? (configSnapshot ? JSON.parse(configSnapshot) : null)
|
|
247
|
+
: configSnapshot;
|
|
248
|
+
} catch {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
// 优先读更具名的 `restart_supervised`(agent-node 同时上报,永远同值);
|
|
252
|
+
// 旧客户端只报 config_update_capable,回退读它。
|
|
253
|
+
const named = parsed?.restart_supervised;
|
|
254
|
+
if (typeof named === "boolean") return named;
|
|
255
|
+
const value = parsed?.config_update_capable;
|
|
256
|
+
return typeof value === "boolean" ? value : null;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* 2026-10-31 —— 双写字段的**分歧**本身是一条读数,而今天它是静默的。
|
|
261
|
+
*
|
|
262
|
+
* `readConfigUpdateCapable` 在两个字段都在时优先读 `restart_supervised`,
|
|
263
|
+
* 文档说它们「永远同值」。所以「不同值」不是噪声,是一个真实信号:
|
|
264
|
+
* 半升级(wrapper 转发了一路、漏了另一路)、旧节点、或有人手改了快照。
|
|
265
|
+
*
|
|
266
|
+
* 🔴 为什么值得单独一个函数:
|
|
267
|
+
* 两个生产者的字段,只要**允许一个遮住另一个**,那个被遮住的值就再也读不到了 ——
|
|
268
|
+
* 而“读不到”与“两个一致”在调用方看来完全一样。这正是隐性回退的通用形状:
|
|
269
|
+
* 值从一个隐式来源解析出来,解析过程不留痕。
|
|
270
|
+
*
|
|
271
|
+
* 返回值:只在**两个都是布尔且不同**时给出两份值;其余一律 null(没有分歧可报)。
|
|
272
|
+
* 调用方负责把 `restart_supervision_flag_divergence` 放进 warnings —— 本函数不改判据。
|
|
273
|
+
*/
|
|
274
|
+
export function configUpdateCapabilityDivergence(
|
|
275
|
+
configSnapshot: unknown,
|
|
276
|
+
): { named: boolean; legacy: boolean } | null {
|
|
277
|
+
let parsed: any = null;
|
|
278
|
+
try {
|
|
279
|
+
parsed = typeof configSnapshot === "string"
|
|
280
|
+
? (configSnapshot ? JSON.parse(configSnapshot) : null)
|
|
281
|
+
: configSnapshot;
|
|
282
|
+
} catch {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
const named = parsed?.restart_supervised;
|
|
286
|
+
const legacy = parsed?.config_update_capable;
|
|
287
|
+
if (typeof named !== "boolean" || typeof legacy !== "boolean") return null;
|
|
288
|
+
return named === legacy ? null : { named, legacy };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 2026-10-31 —— 用节点**自己**报的托管判定取代「没有声明」(#3168 的自然下一步)。
|
|
293
|
+
*
|
|
294
|
+
* `config_update_capable=false` 只说明「没有声明 sentinel-75 重启包装」,
|
|
295
|
+
* 而 systemd/pm2 托管的节点也可能报 false(它们不走那套包装)⇒ 于是只能写成
|
|
296
|
+
* 「does not advertise」,把判断交给调用方 —— 那是对的,但不够具体。
|
|
297
|
+
*
|
|
298
|
+
* 节点现在会上报三态 `systemd_supervision`(supervised / not_supervised / unknown),
|
|
299
|
+
* 于是「它自己说没人拉它」与「它自己说有人拉它」可以被分开讲:
|
|
300
|
+
*
|
|
301
|
+
* not_supervised ⇒ 明确后果:exit 75 之后**没有东西会把它拉起来**
|
|
302
|
+
* supervised ⇒ 不做警告(具名判定优先,胜过 legacy 布尔)
|
|
303
|
+
* unknown/缺失 ⇒ 退回旧口径(「没有声明」),因为「不知道」不能当成「没人拉」
|
|
304
|
+
*
|
|
305
|
+
* 🔴 三态而不是布尔:`unknown` 与 `not_supervised` 在处置上完全相反 ——
|
|
306
|
+
* 前者要人去看,后者要人别发这类变更。
|
|
307
|
+
*/
|
|
308
|
+
export function readSystemdSupervision(
|
|
309
|
+
configSnapshot: unknown,
|
|
310
|
+
): "supervised" | "not_supervised" | "unknown" | null {
|
|
311
|
+
let parsed: any = null;
|
|
312
|
+
try {
|
|
313
|
+
parsed = typeof configSnapshot === "string"
|
|
314
|
+
? (configSnapshot ? JSON.parse(configSnapshot) : null)
|
|
315
|
+
: configSnapshot;
|
|
316
|
+
} catch {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
const v = parsed?.systemd_supervision;
|
|
320
|
+
if (v === "supervised" || v === "not_supervised" || v === "unknown") return v;
|
|
321
|
+
return null; // 老节点没有这个字段:**缺失 ≠ unknown**,缺失是「这一版还不会报」
|
|
322
|
+
}
|
|
323
|
+
|
|
129
324
|
/**
|
|
130
325
|
* Classify the patch's required apply mode. Empty patch (model + flags
|
|
131
326
|
* both empty, no channels) → "restart_only" (used by restart_node tool).
|
|
@@ -134,15 +329,34 @@ export function isAllowedToChangeFlag(
|
|
|
134
329
|
* once at boot in agent-node/src/cli.ts and forks per-channel workers
|
|
135
330
|
* from it, so a channel enable/disable takes effect on process restart
|
|
136
331
|
* only — see #260 P5 wire discipline). Otherwise → "hot".
|
|
332
|
+
*
|
|
333
|
+
* `opts` carries the target node's runtime identity. Callers that omit
|
|
334
|
+
* it get the pre-#3146 behaviour (model ⇒ restart), which is the safe
|
|
335
|
+
* answer for any node we know nothing about.
|
|
137
336
|
*/
|
|
138
337
|
export function computeApplyMode(
|
|
139
338
|
model: string | undefined,
|
|
140
339
|
flags: Record<string, unknown>,
|
|
141
340
|
channels?: string[] | undefined,
|
|
341
|
+
opts?: {
|
|
342
|
+
runtime?: string | null;
|
|
343
|
+
opencodeGeneration?: "v1" | "v2" | null;
|
|
344
|
+
opencodeMode?: string | null;
|
|
345
|
+
},
|
|
142
346
|
): "hot" | "restart" | "restart_only" {
|
|
143
347
|
const fieldCount = (model !== undefined ? 1 : 0) + Object.keys(flags).length + (channels !== undefined ? 1 : 0);
|
|
144
348
|
if (fieldCount === 0) return "restart_only";
|
|
145
|
-
if (model !== undefined)
|
|
349
|
+
if (model !== undefined) {
|
|
350
|
+
if (isHotModelSwitchSupported(
|
|
351
|
+
model,
|
|
352
|
+
flags,
|
|
353
|
+
channels,
|
|
354
|
+
opts?.runtime,
|
|
355
|
+
opts?.opencodeGeneration ?? null,
|
|
356
|
+
opts?.opencodeMode ?? null,
|
|
357
|
+
)) return "hot";
|
|
358
|
+
return "restart";
|
|
359
|
+
}
|
|
146
360
|
if (channels !== undefined) return "restart";
|
|
147
361
|
for (const key of Object.keys(flags)) {
|
|
148
362
|
if (RESTART_REQUIRED_FLAGS.has(key)) return "restart";
|
|
@@ -184,6 +398,7 @@ export function validatePatch(
|
|
|
184
398
|
model: string | undefined,
|
|
185
399
|
flags: Record<string, unknown>,
|
|
186
400
|
channels?: string[] | undefined,
|
|
401
|
+
nodeRuntime?: string | null,
|
|
187
402
|
): { field: string; reason: string } | null {
|
|
188
403
|
if (model !== undefined) {
|
|
189
404
|
if (typeof model !== "string" || model.length === 0 || model.length > 200) {
|
|
@@ -211,6 +426,8 @@ export function validatePatch(
|
|
|
211
426
|
if (!ALLOWED_FLAGS.has(key)) {
|
|
212
427
|
return { field: `flags.${key}`, reason: "not in allowlist" };
|
|
213
428
|
}
|
|
429
|
+
const codexFail = validateCodexConfigFlag(key, val, nodeRuntime ?? null);
|
|
430
|
+
if (codexFail) return codexFail;
|
|
214
431
|
switch (key) {
|
|
215
432
|
case "permissionMode":
|
|
216
433
|
if (
|
|
@@ -239,8 +456,10 @@ export function validatePatch(
|
|
|
239
456
|
}
|
|
240
457
|
break;
|
|
241
458
|
case "timeout":
|
|
242
|
-
|
|
243
|
-
|
|
459
|
+
// #605 —— 与 create_node 同一把尺子(create-node-validate.ts isValidTimeoutMs):
|
|
460
|
+
// 毫秒,0 或 1000..3_600_000;1..999 是「按秒填了」的形状,拒绝而不是给一个亚秒超时。
|
|
461
|
+
if (!isValidTimeoutMs(val)) {
|
|
462
|
+
return { field: "flags.timeout", reason: TIMEOUT_MS_REASON };
|
|
244
463
|
}
|
|
245
464
|
break;
|
|
246
465
|
}
|