@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,43 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { Database } from "bun:sqlite";
|
|
3
|
+
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { SQLiteAdapter } from "./db-adapter";
|
|
7
|
+
import { createSessionForkStore, type ForkEntry } from "./session-fork-store";
|
|
8
|
+
|
|
9
|
+
test("fork journal persists intent and prevents two independent connections claiming the same write", () => {
|
|
10
|
+
const root = mkdtempSync(join(tmpdir(), "fork590-store-"));
|
|
11
|
+
const file = join(root, "journal.db");
|
|
12
|
+
const a = new SQLiteAdapter(new Database(file));
|
|
13
|
+
let b = new SQLiteAdapter(new Database(file));
|
|
14
|
+
try {
|
|
15
|
+
const source = readFileSync(new URL("./db.ts", import.meta.url), "utf8");
|
|
16
|
+
const schema = source.match(/db\.exec\(`(CREATE TABLE IF NOT EXISTS session_fork_requests[\s\S]*?)`\);/)?.[1];
|
|
17
|
+
expect(schema).toBeDefined(); a.exec(schema!);
|
|
18
|
+
const first = createSessionForkStore(a), second = createSessionForkStore(b);
|
|
19
|
+
const e: ForkEntry = { request_id: "fk_test_one", intent_id: "intent_one", operation: "fork",
|
|
20
|
+
networkId: "net_one", nodeId: "node_one", tokenId: "token_row", requester: "user_token_row", requesterUser: "user_one",
|
|
21
|
+
session_id: "ses_source", binding_id: "generation_one", expires_at: 1000, status: "pending" };
|
|
22
|
+
expect(first.reserve(e).request_id).toBe(e.request_id);
|
|
23
|
+
expect(second.reserve({ ...e, request_id: "fk_duplicate" }).request_id).toBe(e.request_id);
|
|
24
|
+
expect(() => second.reserve({ ...e, request_id: "fk_busy", intent_id: "another_intent" })).toThrow();
|
|
25
|
+
expect(second.intent("user_other", e.networkId, e.intent_id)).toBeUndefined();
|
|
26
|
+
expect(first.claim(e, 999)).toBe(true);
|
|
27
|
+
expect(second.claim(e, 999)).toBe(false);
|
|
28
|
+
// Reopen the actual file, not just a new facade over the same connection.
|
|
29
|
+
b.close(); b = new SQLiteAdapter(new Database(file));
|
|
30
|
+
const restarted = createSessionForkStore(b);
|
|
31
|
+
expect(restarted.get(e.request_id)?.status).toBe("in_progress");
|
|
32
|
+
expect(restarted.claim(e, 999)).toBe(false);
|
|
33
|
+
expect(restarted.settle({ ...e, status: "unknown", error: "session_fork_outcome_unknown" }, "in_progress").status).toBe("unknown");
|
|
34
|
+
expect(first.settle({ ...e, status: "done", result: { session_id: "ses_child" } }, "in_progress").status).toBe("unknown");
|
|
35
|
+
expect(first.reserve({ ...e, request_id: "fk_after_unknown" }).status).toBe("unknown");
|
|
36
|
+
expect(first.claim(e, 999)).toBe(false);
|
|
37
|
+
const next = { ...e, request_id: "fk_next", intent_id: "intent_next" };
|
|
38
|
+
expect(first.reserve(next).status).toBe("pending");
|
|
39
|
+
expect(first.claim(next, 1000)).toBe(false);
|
|
40
|
+
expect(first.settle({ ...next, status: "expired", error: "session_control_request_expired" }, "pending").status).toBe("expired");
|
|
41
|
+
expect(first.active()).toEqual([]);
|
|
42
|
+
} finally { a.close(); b.close(); rmSync(root, { recursive: true, force: true }); }
|
|
43
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { DbAdapter } from "./db-adapter";
|
|
2
|
+
|
|
3
|
+
export type ForkEntry = {
|
|
4
|
+
request_id: string; intent_id: string; operation: "fork";
|
|
5
|
+
networkId: string; nodeId: string; tokenId: string; requester: string; requesterUser: string;
|
|
6
|
+
session_id: string; binding_id: string; expires_at: number;
|
|
7
|
+
status: "pending" | "in_progress" | "done" | "failed" | "unknown" | "expired";
|
|
8
|
+
result?: { session_id: string }; error?: string;
|
|
9
|
+
};
|
|
10
|
+
const columns = `request_id,intent_id,network_id,node_id,token_id,requester_token_id,
|
|
11
|
+
requester_user_id,session_id,binding_id,expires_at,status,result_session_id,error`;
|
|
12
|
+
function decode(r: any): ForkEntry | undefined {
|
|
13
|
+
if (!r) return;
|
|
14
|
+
return { request_id: r.request_id, intent_id: r.intent_id, operation: "fork",
|
|
15
|
+
networkId: r.network_id, nodeId: r.node_id, tokenId: r.token_id,
|
|
16
|
+
requester: r.requester_token_id, requesterUser: r.requester_user_id,
|
|
17
|
+
session_id: r.session_id, binding_id: r.binding_id, expires_at: Number(r.expires_at), status: r.status,
|
|
18
|
+
...(r.result_session_id === null ? {} : { result: { session_id: r.result_session_id } }),
|
|
19
|
+
...(r.error === null ? {} : { error: r.error }) };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** No token values or prompts. CAS claims never return to pending, including
|
|
23
|
+
* after timeout, ACK loss, restart or another store instance reading the row. */
|
|
24
|
+
export function createSessionForkStore(db: DbAdapter) {
|
|
25
|
+
const get = (requestId: string) => decode(db.get(`SELECT ${columns} FROM session_fork_requests WHERE request_id=?1`, requestId));
|
|
26
|
+
return {
|
|
27
|
+
get,
|
|
28
|
+
intent(userId: string, networkId: string, intentId: string) {
|
|
29
|
+
return decode(db.get(`SELECT ${columns} FROM session_fork_requests WHERE requester_user_id=?1 AND network_id=?2 AND intent_id=?3`, userId, networkId, intentId));
|
|
30
|
+
},
|
|
31
|
+
active(): ForkEntry[] {
|
|
32
|
+
return db.all(`SELECT ${columns} FROM session_fork_requests WHERE status IN ('pending','in_progress')`).map(r => decode(r)!);
|
|
33
|
+
},
|
|
34
|
+
reserve(e: ForkEntry): ForkEntry {
|
|
35
|
+
db.run(`INSERT INTO session_fork_requests (${columns}) VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,'pending',NULL,NULL)
|
|
36
|
+
ON CONFLICT(requester_user_id,network_id,intent_id) DO NOTHING`,
|
|
37
|
+
[e.request_id,e.intent_id,e.networkId,e.nodeId,e.tokenId,e.requester,e.requesterUser,e.session_id,e.binding_id,e.expires_at]);
|
|
38
|
+
return decode(db.get(`SELECT ${columns} FROM session_fork_requests WHERE requester_user_id=?1 AND network_id=?2 AND intent_id=?3`, e.requesterUser,e.networkId,e.intent_id))!;
|
|
39
|
+
},
|
|
40
|
+
claim(e: ForkEntry, now: number): boolean {
|
|
41
|
+
return db.run(`UPDATE session_fork_requests SET status='in_progress' WHERE request_id=?1 AND status='pending' AND expires_at>?2`, [e.request_id,now]).changes === 1;
|
|
42
|
+
},
|
|
43
|
+
settle(e: ForkEntry, previous: "pending" | "in_progress"): ForkEntry {
|
|
44
|
+
if (e.status === "pending" || e.status === "in_progress") throw Error("fork_transition_invalid");
|
|
45
|
+
if (previous === "pending" && e.status !== "expired" && e.status !== "failed") throw Error("fork_transition_invalid");
|
|
46
|
+
db.run(`UPDATE session_fork_requests SET status=?1,result_session_id=?2,error=?3 WHERE request_id=?4 AND status=?5`,
|
|
47
|
+
[e.status,e.result?.session_id ?? null,e.error ?? null,e.request_id,previous]);
|
|
48
|
+
return get(e.request_id)!;
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { test, expect } from "bun:test";
|
|
2
|
+
import { Database } from "bun:sqlite";
|
|
3
|
+
import { mkdtempSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { sessionProjectCreateSchema, migrateProjectOperationJournal } from "./session-source-admission-store";
|
|
6
|
+
|
|
7
|
+
test("actual old on-disk journal migrates twice and keeps new-session rows and intent tombstones", () => {
|
|
8
|
+
const path = join(mkdtempSync("/work/attach-migration-"), "old.db");
|
|
9
|
+
let sql = new Database(path);
|
|
10
|
+
sql.exec(sessionProjectCreateSchema);
|
|
11
|
+
sql.run(`INSERT INTO session_project_creates
|
|
12
|
+
(request_id,user_id,requester_token_id,network_id,source_node_id,daemon_node_id,daemon_token_id,daemon_instance_id,
|
|
13
|
+
intent_id,selection_scope,snapshot_id,project_id,child_name,accepted_at,expires_at,state,session_id)
|
|
14
|
+
VALUES ('old','u','t','n','s','d','dt','di','intent','scope','snap','oprj_old','child',1,2,'unknown_rotation_required','ses_Old')`);
|
|
15
|
+
sql.close(); sql = new Database(path);
|
|
16
|
+
const adapter = { dialect: "sqlite", all: (q: string) => sql.query(q).all(), exec: (q: string) => sql.exec(q) };
|
|
17
|
+
migrateProjectOperationJournal(adapter); migrateProjectOperationJournal(adapter);
|
|
18
|
+
expect(sql.query("SELECT operation_kind,selected_session_id,project_id,session_id,state FROM session_project_creates").get()).toEqual({
|
|
19
|
+
operation_kind: "project_new_session", selected_session_id: null, project_id: "oprj_old", session_id: "ses_Old", state: "unknown_rotation_required" });
|
|
20
|
+
expect(() => sql.run("INSERT INTO session_project_creates SELECT * FROM session_project_creates")).toThrow();
|
|
21
|
+
sql.close();
|
|
22
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Opt-in, exact SHA verified patched ELF. No new/fork acceptance rerun.
|
|
2
|
+
import { test, expect } from "bun:test";
|
|
3
|
+
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, symlinkSync, existsSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { createSessionSourceTransportWorker } from "../../agent-node/src/runtime/session-source-transport";
|
|
8
|
+
import { createSessionControlPin } from "../../agent-node/src/runtime/session-control-bridge";
|
|
9
|
+
import { observeHostSharedServe } from "../../agent-node/src/runtime/opencode-host-shared-observer";
|
|
10
|
+
import { SOURCE_DIRECTORY_CAPABILITY as DIR } from "../../contracts/session-source-directory";
|
|
11
|
+
import { PROJECT_CREATE_ROOT as P, SESSION_ATTACH_CAPABILITY as CAP } from "../../contracts/session-project-create";
|
|
12
|
+
|
|
13
|
+
const delegated = process.env.TEST4150_NATIVE_ATTACH_DERIVED === "1";
|
|
14
|
+
test.skipIf(!process.env.TEST4150_NATIVE_BINARY)(delegated ? "real patched Linux delegated policy -> one empty existing Session attach, exact CLI registration, zero native mutation" : "real patched Linux existing empty/materialized Session attach, occupied refusal, exact child register and zero attach native writes", async () => {
|
|
15
|
+
const root = mkdtempSync("/work/native-attach-"), home = join(root, "home"), project = join(root, "project"), daemonDir = join(root, "daemon");
|
|
16
|
+
for (const d of [home, project, daemonDir, join(home, ".anet"), join(project, ".anet"), join(project, ".anet", "nodes"), join(daemonDir, ".anet")]) mkdirSync(d, { mode: 0o700 });
|
|
17
|
+
process.env.COMMHUB_DB = join(root, "hub.db"); process.env.COMMHUB_SOURCE_DIRECTORY_PREVIEW = "1"; process.env.COMMHUB_SESSION_ATTACH_PREVIEW = "1";
|
|
18
|
+
delete process.env.COMMHUB_PROJECT_NEW_SESSION_PREVIEW; delete process.env.COMMHUB_SOURCE_FORK_PREVIEW;
|
|
19
|
+
let providerCalls = 0, stage = "start", attachWrites: string[] = [], fixtureWrites: string[] = [], preparing = true;
|
|
20
|
+
const provider = Bun.serve({ hostname: "127.0.0.1", port: 0, async fetch(r) {
|
|
21
|
+
providerCalls++; if (providerCalls > 4 || new URL(r.url).pathname !== "/v1/chat/completions" || r.method !== "POST") return new Response("refused", { status: 400 });
|
|
22
|
+
const body = await r.json() as any, base = { id: "chatcmpl-attach-fixture", created: 1, model: "test-model" };
|
|
23
|
+
if (!body.stream) return Response.json({ ...base, object: "chat.completion", choices: [{ index: 0, message: { role: "assistant", content: "ATTACH_FIXTURE_COMPLETE" }, finish_reason: "stop" }] });
|
|
24
|
+
return new Response([
|
|
25
|
+
{ ...base, object: "chat.completion.chunk", choices: [{ index: 0, delta: { role: "assistant", content: "ATTACH_FIXTURE_COMPLETE" }, finish_reason: null }] },
|
|
26
|
+
{ ...base, object: "chat.completion.chunk", choices: [{ index: 0, delta: {}, finish_reason: "stop" }], usage: { prompt_tokens: 8, completion_tokens: 4, total_tokens: 12 } },
|
|
27
|
+
].map(c => `data: ${JSON.stringify(c)}\n\n`).join("") + "data: [DONE]\n\n", { headers: { "content-type": "text/event-stream" } });
|
|
28
|
+
} });
|
|
29
|
+
const configEnv = { OPENCODE_SERVER_PASSWORD: "attach-sandbox-only", OPENCODE_CONFIG_CONTENT: JSON.stringify({ model: "test-provider/test-model", enabled_providers: ["test-provider"],
|
|
30
|
+
provider: { "test-provider": { npm: "@ai-sdk/openai-compatible", options: { baseURL: `http://127.0.0.1:${provider.port}/v1`, apiKey: "synthetic" }, models: { "test-model": { name: "test-model", limit: { context: 128000, output: 16000 } } } } } }) };
|
|
31
|
+
const reservation = Bun.serve({ hostname: "127.0.0.1", port: 0, fetch: () => new Response("") }); const port = reservation.port; reservation.stop(true);
|
|
32
|
+
const url = `http://127.0.0.1:${port}`, binary = process.env.TEST4150_NATIVE_BINARY!, identity = process.env.TEST4150_NATIVE_IDENTITY!;
|
|
33
|
+
const native = spawn(binary, ["serve", "--hostname", "127.0.0.1", "--port", String(port)], { cwd: project, env: { ...process.env, ...configEnv, HOME: home }, stdio: ["ignore", "pipe", "pipe"] });
|
|
34
|
+
const originalFetch = globalThis.fetch;
|
|
35
|
+
let worker: ReturnType<typeof createSessionSourceTransportWorker> | undefined, hub: any, db: any;
|
|
36
|
+
globalThis.fetch = (async (input: any, init: any) => {
|
|
37
|
+
const u = new URL(typeof input === "string" || input instanceof URL ? String(input) : input.url), method = init?.method ?? input?.method ?? "GET";
|
|
38
|
+
if (u.origin === url && !["GET", "HEAD"].includes(method)) (preparing ? fixtureWrites : attachWrites).push(`${method} ${u.pathname}`);
|
|
39
|
+
const r = await originalFetch(input, init);
|
|
40
|
+
if (u.pathname === `${P}/child-register`) console.log("NATIVE_ATTACH_REGISTER_HTTP", r.status);
|
|
41
|
+
return r;
|
|
42
|
+
}) as typeof fetch;
|
|
43
|
+
const nativeApi = async (path: string, body?: object) => { const r = await fetch(url + path, { method: body ? "POST" : "GET", signal: AbortSignal.timeout(15000),
|
|
44
|
+
headers: { authorization: `Basic ${Buffer.from("opencode:attach-sandbox-only").toString("base64")}`, "content-type": "application/json", "x-opencode-directory": project },
|
|
45
|
+
...(body ? { body: JSON.stringify(body) } : {}) }); expect(r.ok).toBe(true); return r.status === 204 ? null : r.json() as any; };
|
|
46
|
+
try {
|
|
47
|
+
await new Promise<void>((resolve, reject) => { const t = setTimeout(() => reject(Error("native_start_timeout")), 15000); let text = "";
|
|
48
|
+
const onData = (b: Buffer) => { text = (text + String(b)).slice(-32768); if (text.includes(url)) { clearTimeout(t); resolve(); } };
|
|
49
|
+
native.stdout!.on("data", onData); native.stderr!.on("data", onData); native.once("exit", () => { clearTimeout(t); reject(Error("native_early_exit")); }); });
|
|
50
|
+
const info = await nativeApi("/api/info"); expect(info.version).toBe(identity); expect(info.pid).toBe(native.pid);
|
|
51
|
+
stage = "prepare-existing-sessions";
|
|
52
|
+
const empty = (await nativeApi("/api/session", { title: "Empty attach fixture", location: { directory: project } })).data.id;
|
|
53
|
+
const materialized = delegated ? empty : (await nativeApi("/api/session", { title: "Materialized attach fixture", location: { directory: project } })).data.id;
|
|
54
|
+
if (!delegated) {
|
|
55
|
+
await nativeApi(`/api/session/${materialized}/prompt`, { text: "Reply ATTACH_FIXTURE_COMPLETE, no tools.", resume: true });
|
|
56
|
+
const wait = await fetch(`${url}/api/experimental/session/${materialized}/wait`, { method: "POST", signal: AbortSignal.timeout(15000),
|
|
57
|
+
headers: { authorization: `Basic ${Buffer.from("opencode:attach-sandbox-only").toString("base64")}`, "x-opencode-directory": project } }); expect(wait.status).toBe(204);
|
|
58
|
+
}
|
|
59
|
+
const selectedIds = delegated ? [empty] : [empty, materialized];
|
|
60
|
+
const before = new Map<string, any>();
|
|
61
|
+
for (const id of selectedIds) before.set(id, { info: await nativeApi(`/api/session/${id}`), context: await nativeApi(`/api/session/${id}/context`) });
|
|
62
|
+
expect(before.get(empty).context.data).toEqual([]); if (!delegated) expect(JSON.stringify(before.get(materialized).context)).toContain("ATTACH_FIXTURE_COMPLETE");
|
|
63
|
+
console.log("NATIVE_ATTACH_FIXTURE", JSON.stringify({ emptyMessages: 0, materializedMessages: before.get(materialized).context.data.length, fixtureWrites, providerCalls }));
|
|
64
|
+
({ db } = await import("./db")); const { register, createNetworkTokenForNode } = await import("./auth"); register("attach_bootstrap", "Synthetic-Attach-4150!");
|
|
65
|
+
const human = register("attach_owner", "Synthetic-Attach-4150!"), net = human.network_id;
|
|
66
|
+
const daemon = createNetworkTokenForNode(human.user.user_id, net, "attach-daemon", "attach_daemon"); createNetworkTokenForNode(human.user.user_id, net, "attach-source", "attach_source");
|
|
67
|
+
db.run("UPDATE nodes SET runtime='opencode-cli', config_snapshot=?1 WHERE node_id='attach_source'", [JSON.stringify({ flags: { opencodeGeneration: "v2", opencodeMode: "copresence" } })]);
|
|
68
|
+
db.run("UPDATE nodes SET config_snapshot=?1 WHERE node_id='attach_daemon'", [JSON.stringify({ role: "host_supervisor", daemon_capabilities: { source_directory_read: DIR, session_attach: CAP } })]);
|
|
69
|
+
db.run("INSERT INTO sessions (resume_id,alias,node_id,network_id,env_transport,last_seen_at) VALUES ('attach_daemon','attach-daemon','attach_daemon',?1,'loopback',datetime('now'))", [net]);
|
|
70
|
+
writeFileSync(join(home, ".anet", "password"), "attach-sandbox-only", { mode: 0o600 });
|
|
71
|
+
writeFileSync(join(home, ".anet", "opencode-shared-server.json"), JSON.stringify({ url, passwordFile: join(home, ".anet", "password") }), { mode: 0o600 });
|
|
72
|
+
const observed = observeHostSharedServe(url); expect(observed.ok).toBe(true); if (!observed.ok) throw Error("native_observation_refused");
|
|
73
|
+
const serverId = `osrv_${randomUUID()}`;
|
|
74
|
+
const grants = selectedIds.map(session_id => ({ grant_id: randomUUID(), daemon_id: "attach_daemon", directory: project, session_id,
|
|
75
|
+
server_pid: observed.processEvidence.pid, server_start_ticks: observed.processEvidence.startTicks, expires_at: Date.now() + 180000 }));
|
|
76
|
+
const grantPath = join(daemonDir, ".anet", "opencode-directory-authorities.json");
|
|
77
|
+
const policy = { enabled: true, policy_id: randomUUID(), daemon_id: "attach_daemon", directories: [project], expires_at: Date.now() + 86400000, grant_ttl_ms: 120000 };
|
|
78
|
+
const writeGrants = () => writeFileSync(grantPath, JSON.stringify({ version: 1, grants: [{ server_id: serverId, network_id: net, source_node_id: "attach_source", directories: [project], opencode_unsafe_tools: true,
|
|
79
|
+
...(delegated ? { allow_attach_existing: policy } : { attach_sessions: grants }) }] }), { mode: 0o600 }); writeGrants();
|
|
80
|
+
if (delegated) { const text = readFileSync(grantPath, "utf8"); expect(text).not.toContain(empty); expect(text).not.toContain("server_pid"); expect(text).not.toContain("server_start_ticks"); }
|
|
81
|
+
const { bootServer } = await import("./server"); hub = bootServer({ hostname: "127.0.0.1", port: 0 }); const hubUrl = `http://127.0.0.1:${hub.port}`;
|
|
82
|
+
const pkg = join(root, "node_modules", "@sleep2agi", "agent-node"); mkdirSync(pkg, { recursive: true }); writeFileSync(join(pkg, "package.json"), readFileSync(join(import.meta.dir, "../../agent-node/package.json")));
|
|
83
|
+
for (const dep of ["@anthropic-ai", "@openai", "node-pty"]) symlinkSync(join(import.meta.dir, "../../agent-node/node_modules", dep), join(root, "node_modules", dep));
|
|
84
|
+
const built = await Bun.build({ entrypoints: [join(import.meta.dir, "../../agent-node/src/cli.ts")], outdir: join(pkg, "dist"), target: "bun", external: ["@anthropic-ai/claude-agent-sdk", "@openai/codex-sdk", "node-pty"] }); expect(built.success).toBe(true);
|
|
85
|
+
mkdirSync(join(root, "bin")); symlinkSync(binary, join(root, "bin", "opencode")); mkdirSync(join(root, "safe"), { mode: 0o700 });
|
|
86
|
+
const auditPath = join(root, "child-native-audit.jsonl");
|
|
87
|
+
worker = createSessionSourceTransportWorker({ hubUrl, home, daemonWorkDir: daemonDir, directoryEnabled: true, projectEnabled: false, attachEnabled: true, forkEnabled: false,
|
|
88
|
+
nativeLaunch: { command: process.execPath, argsPrefix: [join(import.meta.dir, "../../agent-network/bin/cli.ts")], timeoutMs: 12000,
|
|
89
|
+
env: { ...process.env, ...configEnv, HOME: home, PATH: `${join(root, "bin")}:/usr/local/bin:/usr/bin:/bin`, ANET_AGENT_NODE_BIN: join(pkg, "dist", "cli.js"), ANET_OPENCODE_SAFE_BASE: join(root, "safe"), TEST4150_NATIVE_ORIGIN: url, TEST4150_NATIVE_AUDIT: auditPath } },
|
|
90
|
+
pin: createSessionControlPin({ hubUrl, token: daemon.token, nodeId: "attach_daemon", networkId: net, epoch: 0, currentEpoch: () => 0, currentToken: () => daemon.token, signal: new AbortController().signal }) });
|
|
91
|
+
const api = async (path: string, body?: any) => { const r = await fetch(hubUrl + path, { method: body ? "POST" : "GET", headers: { authorization: `Bearer ${human.token}`, "content-type": "application/json" }, ...(body ? { body: JSON.stringify(body) } : {}) }); expect(r.status).toBe(200); return r.json() as any; };
|
|
92
|
+
const D = "/api/node-session-control/source/directory", selection = { network_id: net, source_node_id: "attach_source", daemon_node_id: "attach_daemon" };
|
|
93
|
+
const snapshot = async () => { await worker!.tick(); const q = await api(D, selection); await worker!.tick(); const q2 = await api(D, { ...selection, selection_scope: q.request_id, server_id: serverId }); await worker!.tick(); return { q: q2, s: (await api(`${D}/${q2.request_id}?network_id=${net}`)).snapshot }; };
|
|
94
|
+
preparing = false; stage = "attach-existing"; const providerBeforeAttach = providerCalls;
|
|
95
|
+
const children: Array<{ id: string; health: any }> = [];
|
|
96
|
+
for (const [i, id] of selectedIds.entries()) {
|
|
97
|
+
const { q, s } = await snapshot(); expect(s.sessions).toHaveLength(selectedIds.length);
|
|
98
|
+
const selected = s.sessions.find((v: any) => v.title === (i === 0 ? "Empty attach fixture" : "Materialized attach fixture")); expect(selected).toBeDefined();
|
|
99
|
+
const intent = { selection_scope: q.request_id, snapshot_id: s.snapshot_id, session_id: selected.session_id, child_name: `attached-${i}`, intent_id: `attach-${i}` };
|
|
100
|
+
const receipt = await api(P, intent); await worker.tick(); const result = await api(`${P}/${receipt.request_id}?network_id=${net}`);
|
|
101
|
+
console.log("NATIVE_ATTACH_RECEIPT", JSON.stringify({ status: result.status, operation_kind: result.operation_kind, session_creation: result.session_creation }));
|
|
102
|
+
expect(result.status).toBe("registration_confirmed"); expect(result.session_creation).toBe("not_performed"); expect(result.registration_is_health).toBe(false);
|
|
103
|
+
const row = db.get("SELECT * FROM session_project_creates WHERE request_id=?1", receipt.request_id); expect(row.session_id).toBe(id);
|
|
104
|
+
const h = JSON.parse(readFileSync(join(project, ".anet", "nodes", `attached-${i}`, "source-resume-health.json"), "utf8")); expect(h.session_id).toBe(id); children.push({ id, health: h });
|
|
105
|
+
const tokens = db.get("SELECT COUNT(*) n FROM api_tokens").n; expect((await api(P, intent)).request_id).toBe(receipt.request_id); await worker.tick(); expect(db.get("SELECT COUNT(*) n FROM api_tokens").n).toBe(tokens);
|
|
106
|
+
expect(await nativeApi(`/api/session/${id}`)).toEqual(before.get(id).info); expect(await nativeApi(`/api/session/${id}/context`)).toEqual(before.get(id).context);
|
|
107
|
+
}
|
|
108
|
+
if (!delegated) {
|
|
109
|
+
stage = "occupied-refusal"; for (const grant of grants) grant.grant_id = randomUUID(); writeGrants(); const { q, s } = await snapshot();
|
|
110
|
+
const beforeTokens = db.get("SELECT COUNT(*) n FROM api_tokens").n;
|
|
111
|
+
const r = await api(P, { selection_scope: q.request_id, snapshot_id: s.snapshot_id, session_id: s.sessions[0].session_id, child_name: "occupied-attempt", intent_id: "occupied" }); await worker.tick();
|
|
112
|
+
expect((await api(`${P}/${r.request_id}?network_id=${net}`)).status).toBe("unknown_rotation_required"); expect(db.get("SELECT COUNT(*) n FROM api_tokens").n).toBe(beforeTokens);
|
|
113
|
+
}
|
|
114
|
+
for (const c of children) expect(() => process.kill(c.health.pid, 0)).not.toThrow();
|
|
115
|
+
await worker.stop(); for (const c of children) { expect(() => process.kill(c.health.pid, 0)).toThrow(); expect(await nativeApi(`/api/session/${c.id}/context`)).toEqual(before.get(c.id).context); }
|
|
116
|
+
expect((await nativeApi("/api/info")).pid).toBe(native.pid); expect(providerCalls).toBe(providerBeforeAttach); expect(attachWrites).toEqual([]);
|
|
117
|
+
const audit = existsSync(auditPath) ? readFileSync(auditPath, "utf8").trim().split("\n").filter(Boolean).map(l => JSON.parse(l)) : []; expect(audit.length).toBeGreaterThan(0); expect(audit.filter(v => v.method !== "GET")).toEqual([]);
|
|
118
|
+
console.log("NATIVE_ATTACH_ACCEPTANCE", JSON.stringify({ identity, stock: false, delegated, fixtureWrites, providerCalls, attachWrites, childWrites: 0, registeredChildren: children.length, occupiedRefused: !delegated, preservedContext: true, sameServer: true, childStopPreservedSessions: true, platform: "linux" }));
|
|
119
|
+
} catch (e) { console.error("NATIVE_ATTACH_FIRST_FAILURE", JSON.stringify({ stage, fixtureWrites, attachWrites, providerCalls })); throw e; }
|
|
120
|
+
finally { await worker?.stop(); globalThis.fetch = originalFetch; hub?.stop(true); provider.stop(true); if (native.exitCode === null && native.signalCode === null) { native.kill("SIGTERM"); await new Promise<void>(resolve => { const t = setTimeout(() => { native.kill("SIGKILL"); resolve(); }, 1500); native.once("exit", () => { clearTimeout(t); resolve(); }); }); } db?.close(); }
|
|
121
|
+
}, 60000);
|