@wrongstack/core 0.313.0 → 0.316.1
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/dist/chronicle/index.js +84 -6391
- package/dist/chronicle/legacy-journal-import.d.ts +0 -6
- package/dist/chronicle/metrics-ingest.d.ts +14 -0
- package/dist/chronicle/metrics-schema.d.ts +10 -1
- package/dist/chronicle/metrics-store.d.ts +20 -2
- package/dist/chronicle/project-server.js +98 -4874
- package/dist/chronicle/sink.d.ts +13 -0
- package/dist/chronicle/sqlite-journal.d.ts +20 -2
- package/dist/chunk-25LSLC3G.js +334 -0
- package/dist/chunk-27QIURLN.js +1073 -0
- package/dist/chunk-2FK4WTFF.js +207 -0
- package/dist/chunk-2YU4WVBW.js +134 -0
- package/dist/chunk-3AGWVSS7.js +4608 -0
- package/dist/chunk-3BDV7RL3.js +211 -0
- package/dist/chunk-3ECENVHL.js +325 -0
- package/dist/chunk-3XPVB7BA.js +135 -0
- package/dist/chunk-45WI72ZB.js +16884 -0
- package/dist/chunk-4BMVPOHO.js +3748 -0
- package/dist/chunk-4I7HGVVA.js +363 -0
- package/dist/chunk-4LCZVJVF.js +317 -0
- package/dist/chunk-4SJNS7OB.js +217 -0
- package/dist/chunk-4VWO3ZXL.js +342 -0
- package/dist/chunk-57GEWK5X.js +26 -0
- package/dist/chunk-5BMIE7QG.js +46 -0
- package/dist/chunk-5S437PRC.js +50 -0
- package/dist/chunk-5XDUGTKN.js +511 -0
- package/dist/chunk-5YPSXQXM.js +1443 -0
- package/dist/chunk-6FHWXLPT.js +10 -0
- package/dist/chunk-6H5GEOET.js +2406 -0
- package/dist/chunk-6NWEVFEL.js +151 -0
- package/dist/chunk-AYW5YINX.js +58 -0
- package/dist/chunk-B4AMLZPB.js +9 -0
- package/dist/chunk-B7F4WVP4.js +65 -0
- package/dist/chunk-BJHVULHO.js +55 -0
- package/dist/chunk-BPBKKBUK.js +2085 -0
- package/dist/chunk-BYD345OX.js +589 -0
- package/dist/chunk-C27KDLOX.js +279 -0
- package/dist/chunk-CU546ESW.js +597 -0
- package/dist/chunk-DLHHXUAM.js +172 -0
- package/dist/chunk-DOTHQSJ2.js +429 -0
- package/dist/chunk-DYLPMV4Q.js +711 -0
- package/dist/chunk-EODDVJBM.js +82 -0
- package/dist/chunk-F3JWNST7.js +361 -0
- package/dist/chunk-FC2ZGRF3.js +140 -0
- package/dist/chunk-FCBTO76Z.js +5786 -0
- package/dist/chunk-FHZVFYSL.js +396 -0
- package/dist/chunk-FNXVT7HF.js +52 -0
- package/dist/chunk-FWNLEZYG.js +259 -0
- package/dist/chunk-FXQLIX3K.js +211 -0
- package/dist/chunk-G5S3S5ZN.js +38 -0
- package/dist/chunk-GDQ7CZRQ.js +116 -0
- package/dist/chunk-GJJGJB2R.js +1374 -0
- package/dist/chunk-GTCU6DZ3.js +1 -0
- package/dist/chunk-HA4ZYA6T.js +178 -0
- package/dist/chunk-HI3JGZR2.js +188 -0
- package/dist/chunk-HMLIGAU7.js +395 -0
- package/dist/chunk-HXKZ7OBQ.js +303 -0
- package/dist/chunk-I7DALG7J.js +292 -0
- package/dist/chunk-IRUTEHCE.js +960 -0
- package/dist/chunk-IYFBFX34.js +86 -0
- package/dist/chunk-J2WRWR37.js +1104 -0
- package/dist/chunk-JFPJ6LLQ.js +129 -0
- package/dist/chunk-JMULFFLN.js +9 -0
- package/dist/chunk-JO4MGB6Z.js +1264 -0
- package/dist/chunk-JVKB2TBL.js +48 -0
- package/dist/chunk-JX7VBZDK.js +31 -0
- package/dist/chunk-K6BXGITA.js +931 -0
- package/dist/chunk-KDQJCT2J.js +45 -0
- package/dist/chunk-KJ2ZTQSL.js +47 -0
- package/dist/chunk-KZMSZV32.js +187 -0
- package/dist/chunk-LA7CLDRW.js +129 -0
- package/dist/chunk-LHOA5DWA.js +28 -0
- package/dist/chunk-LSMMOS2Z.js +119 -0
- package/dist/chunk-LX5QWLBL.js +27 -0
- package/dist/chunk-LXWCMQNJ.js +789 -0
- package/dist/chunk-M27LIEKV.js +2829 -0
- package/dist/chunk-MJPHJRAL.js +663 -0
- package/dist/chunk-MTL4O5YR.js +228 -0
- package/dist/chunk-NDBIPFNY.js +102 -0
- package/dist/chunk-NEMIWEXC.js +1199 -0
- package/dist/chunk-NHJ75HXY.js +1 -0
- package/dist/chunk-NIOAGFPB.js +1510 -0
- package/dist/chunk-NS52ISWS.js +355 -0
- package/dist/chunk-NSOFPKGT.js +5352 -0
- package/dist/chunk-NVIZG63R.js +757 -0
- package/dist/chunk-O37BQ65S.js +21 -0
- package/dist/chunk-OOYZPOXM.js +308 -0
- package/dist/chunk-OSGLYW5J.js +28 -0
- package/dist/chunk-PFCMSSUF.js +1640 -0
- package/dist/chunk-PFZO3C6H.js +14 -0
- package/dist/chunk-PGRVXIMY.js +158 -0
- package/dist/chunk-PHH7LD45.js +113 -0
- package/dist/chunk-PISBFBJN.js +109 -0
- package/dist/chunk-POOOIWE5.js +9 -0
- package/dist/chunk-PQNS3U7Z.js +1240 -0
- package/dist/chunk-QSTSJOCK.js +402 -0
- package/dist/chunk-RFQMOKWK.js +282 -0
- package/dist/chunk-RJIZEJ42.js +30 -0
- package/dist/chunk-RTOTNK3P.js +484 -0
- package/dist/chunk-RXKSDUAU.js +1172 -0
- package/dist/chunk-S45JPKQN.js +3317 -0
- package/dist/chunk-SAFHACFA.js +152 -0
- package/dist/chunk-SQJVFEBV.js +41 -0
- package/dist/chunk-SVT4RNTR.js +49 -0
- package/dist/chunk-SWUFN7XM.js +43 -0
- package/dist/chunk-SXMVYC5H.js +174 -0
- package/dist/chunk-SZ6AYUIZ.js +23 -0
- package/dist/chunk-TBRL2RCC.js +9 -0
- package/dist/chunk-TCCHINEF.js +655 -0
- package/dist/chunk-THEGTRAG.js +316 -0
- package/dist/chunk-TR4LQE7L.js +2256 -0
- package/dist/chunk-TRT2HRWZ.js +18 -0
- package/dist/chunk-TWJMGXCI.js +900 -0
- package/dist/chunk-U45AXT5D.js +1023 -0
- package/dist/chunk-U4FWBSO3.js +509 -0
- package/dist/chunk-UBGDX6FI.js +147 -0
- package/dist/chunk-UJILKYES.js +75 -0
- package/dist/chunk-ULMAQV3T.js +234 -0
- package/dist/chunk-VVBP6KGT.js +9 -0
- package/dist/chunk-W5VITDM2.js +168 -0
- package/dist/chunk-WAHQVNWT.js +194 -0
- package/dist/chunk-WBPVKEEE.js +227 -0
- package/dist/chunk-WGGYRBXH.js +5434 -0
- package/dist/chunk-WLYKU45P.js +5770 -0
- package/dist/chunk-WP7BVANJ.js +53 -0
- package/dist/chunk-WQQON3SV.js +473 -0
- package/dist/chunk-WQTOVMGV.js +119 -0
- package/dist/chunk-XBDP4QPW.js +7 -0
- package/dist/chunk-XEBHSJLT.js +103 -0
- package/dist/chunk-XF4VUMKW.js +231 -0
- package/dist/chunk-XQ2ECNK3.js +1 -0
- package/dist/chunk-Y5YXDM7D.js +74 -0
- package/dist/chunk-YOPAUVU4.js +2588 -0
- package/dist/chunk-YPT4A46F.js +362 -0
- package/dist/chunk-YWXT3JNM.js +425 -0
- package/dist/chunk-YY6APYUM.js +49 -0
- package/dist/chunk-Z2IJUO45.js +691 -0
- package/dist/chunk-ZHZ2Y2DH.js +1643 -0
- package/dist/chunk-ZT7JNIGX.js +152 -0
- package/dist/coordination/agent-monitor.d.ts +9 -1
- package/dist/coordination/agent-subagent-runner.d.ts +1 -1
- package/dist/coordination/agents/agent-prompts.d.ts +8 -0
- package/dist/coordination/agents/index.d.ts +33 -1
- package/dist/coordination/agents/index.js +184 -6269
- package/dist/coordination/agents/phase3-wave1-platform.d.ts +1 -3
- package/dist/coordination/agents/phase3-wave2-meta.d.ts +1 -3
- package/dist/coordination/agents/phase8-wave3-products.d.ts +1 -3
- package/dist/coordination/agents/phase9-wave4-platform-meta.d.ts +1 -3
- package/dist/coordination/agents/project-agent-identity.d.ts +11 -11
- package/dist/coordination/agents/types.d.ts +13 -2
- package/dist/coordination/brain-monitor.d.ts +30 -7
- package/dist/coordination/collab-debug.d.ts +1 -1
- package/dist/coordination/collab-pause.d.ts +1 -1
- package/dist/coordination/delegate-tool.d.ts +7 -5
- package/dist/coordination/director-kanban-queue-helpers.d.ts +1 -0
- package/dist/coordination/director-options.d.ts +7 -0
- package/dist/coordination/director-spawn-model.d.ts +17 -0
- package/dist/coordination/director-tools.d.ts +2 -2
- package/dist/coordination/director.d.ts +12 -0
- package/dist/coordination/dispatcher.d.ts +8 -0
- package/dist/coordination/fleet-bus.d.ts +35 -4
- package/dist/coordination/fleet-supervisor.d.ts +10 -2
- package/dist/coordination/fleet.d.ts +16 -7
- package/dist/coordination/index.d.ts +4 -0
- package/dist/coordination/index.js +402 -34324
- package/dist/coordination/kanban-dispatch-port.d.ts +2 -2
- package/dist/coordination/mailbox-http-router.d.ts +4 -3
- package/dist/coordination/mailbox-http-validation.d.ts +1 -1
- package/dist/coordination/mailbox-project-server.js +48 -3276
- package/dist/coordination/mailbox-types.d.ts +24 -6
- package/dist/coordination/model-tier-leader.d.ts +122 -0
- package/dist/coordination/model-tier.d.ts +122 -0
- package/dist/coordination/multi-agent-coordinator.d.ts +24 -0
- package/dist/coordination/origin-session.d.ts +16 -0
- package/dist/coordination/provider-status-tracker.d.ts +41 -5
- package/dist/coordination/session-note-hub.d.ts +44 -0
- package/dist/coordination/session-note-tool.d.ts +10 -0
- package/dist/core/agent.d.ts +15 -2
- package/dist/core/context.d.ts +22 -3
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +239 -12360
- package/dist/core/model-ref.js +5 -23
- package/dist/core/provider-runner.d.ts +36 -1
- package/dist/core/request-conversation-binding.d.ts +37 -0
- package/dist/core/session-notes.d.ts +25 -0
- package/dist/core/system-prompt-builder.d.ts +11 -2
- package/dist/core/system-prompt-variants.d.ts +78 -0
- package/dist/design/index.js +50 -1087
- package/dist/execution/auto-compaction-middleware.d.ts +11 -0
- package/dist/execution/autonomy-brain.d.ts +2 -1
- package/dist/execution/autonomy-prompt-contributor.d.ts +7 -2
- package/dist/execution/compaction-core.d.ts +4 -4
- package/dist/execution/eternal-autonomy.d.ts +1 -1
- package/dist/execution/index.d.ts +1 -1
- package/dist/execution/index.js +1615 -21895
- package/dist/execution/model-runtime.d.ts +0 -7
- package/dist/execution/parallel-eternal-engine.d.ts +7 -7
- package/dist/execution/prompt-enhancer.js +16 -535
- package/dist/execution/retry-policy.d.ts +31 -1
- package/dist/extension/index.js +7 -311
- package/dist/goal/index.js +33 -3435
- package/dist/hooks/index.js +14 -1138
- package/dist/hq/index.js +114 -5139
- package/dist/hq/persistence/event-log.d.ts +0 -1
- package/dist/hq/persistence.d.ts +4 -4
- package/dist/hq/protocol.js +21 -668
- package/dist/hq/publisher.d.ts +2 -0
- package/dist/index.d.ts +14 -11
- package/dist/index.js +1502 -92655
- package/dist/infrastructure/index.d.ts +4 -4
- package/dist/infrastructure/index.js +504 -5230
- package/dist/infrastructure/token-counter.d.ts +9 -0
- package/dist/kernel/events/agent-events.d.ts +77 -3
- package/dist/kernel/events/brain-events.d.ts +12 -0
- package/dist/kernel/events/provider-events.d.ts +22 -1
- package/dist/kernel/events/session-events.d.ts +14 -0
- package/dist/kernel/events/tool-events.d.ts +13 -0
- package/dist/kernel/index.js +14 -992
- package/dist/mailbox-attach.d.ts +1 -1
- package/dist/models/index.js +41 -1117
- package/dist/notifications/index.js +3 -108
- package/dist/observability/event-bridge.d.ts +25 -5
- package/dist/observability/index.d.ts +9 -8
- package/dist/observability/index.js +477 -631
- package/dist/observability/tool-usage-source.d.ts +65 -0
- package/dist/plugin/index.d.ts +5 -0
- package/dist/plugin/index.js +600 -14835
- package/dist/plugins/auto-review-plugin.d.ts +3 -2
- package/dist/plugins/review-finding-commands.d.ts +0 -8
- package/dist/plugins/review-finding-store.js +22 -0
- package/dist/plugins/review-finding-types.js +19 -0
- package/dist/plugins/review-report-integration.js +21 -0
- package/dist/plugins/review-report-store.js +20 -0
- package/dist/plugins/review-report-types.js +13 -0
- package/dist/prompts/index.js +14 -948
- package/dist/registry/index.js +9 -822
- package/dist/registry/tool-registry.d.ts +59 -9
- package/dist/registry-7N4O3E7W.js +14 -0
- package/dist/replay/index.js +6 -84
- package/dist/security/capabilities.d.ts +6 -0
- package/dist/security/file-permissions.d.ts +1 -1
- package/dist/security/index.js +161 -2235
- package/dist/security/permission-policy.d.ts +12 -1
- package/dist/security/secret-scrubber.d.ts +15 -0
- package/dist/session-catalog/index.d.ts +1 -0
- package/dist/session-catalog/index.js +41 -2103
- package/dist/session-catalog/project-server.js +59 -1435
- package/dist/session-catalog/protocol.d.ts +32 -1
- package/dist/session-catalog/registry.d.ts +17 -1
- package/dist/session-catalog/session-agents.d.ts +56 -0
- package/dist/session-catalog/store-rebuild.d.ts +14 -0
- package/dist/session-catalog/store-schema.d.ts +26 -0
- package/dist/session-catalog/store.d.ts +27 -1
- package/dist/session-note-attach.d.ts +9 -0
- package/dist/skills/index.js +35 -1578
- package/dist/statusline/index.d.ts +43 -0
- package/dist/statusline/index.js +102 -0
- package/dist/storage/board-store-port.d.ts +2 -2
- package/dist/storage/config-loader/in-project-policy.d.ts +29 -0
- package/dist/storage/config-loader.d.ts +3 -2
- package/dist/storage/file-session-writer.d.ts +4 -2
- package/dist/storage/goal-coordination.d.ts +6 -1
- package/dist/storage/goal-kanban.d.ts +4 -1
- package/dist/storage/index.d.ts +12 -4
- package/dist/storage/index.js +198 -15601
- package/dist/storage/input-history-store.d.ts +2 -4
- package/dist/storage/memory-curator.d.ts +133 -0
- package/dist/storage/session-agent-attribution.d.ts +39 -0
- package/dist/storage/session-doctor.d.ts +109 -0
- package/dist/storage/session-event-bridge.d.ts +5 -7
- package/dist/storage/session-outcome.d.ts +42 -0
- package/dist/storage/session-recovery.d.ts +55 -0
- package/dist/storage/session-store/load-session-data.d.ts +11 -0
- package/dist/storage/session-store/prune-helpers.d.ts +1 -1
- package/dist/storage/session-store/resume-session.d.ts +0 -2
- package/dist/storage/session-store/types.d.ts +8 -0
- package/dist/storage/session-store.d.ts +3 -3
- package/dist/storage/session-summary-tracker.d.ts +8 -1
- package/dist/storage/session-write-buffer.d.ts +18 -0
- package/dist/storage/session-writer-truncate.d.ts +2 -0
- package/dist/tasking/index.js +10 -676
- package/dist/tools/fallback-manage-tools.d.ts +6 -4
- package/dist/tools/index.js +52 -9590
- package/dist/tools/model-tier-set-tool.d.ts +66 -0
- package/dist/types/agent-bridge.d.ts +2 -1
- package/dist/types/config/autonomy.d.ts +5 -0
- package/dist/types/config/mcp-features.d.ts +7 -0
- package/dist/types/config/model-tiers.d.ts +148 -0
- package/dist/types/config/root.d.ts +9 -0
- package/dist/types/config/tools.d.ts +73 -0
- package/dist/types/config/ui.d.ts +1 -1
- package/dist/types/config.d.ts +1 -0
- package/dist/types/context.d.ts +2 -0
- package/dist/types/default-config.d.ts +6 -0
- package/dist/types/errors.d.ts +20 -1
- package/dist/types/index.d.ts +11 -9
- package/dist/types/index.js +131 -1342
- package/dist/types/multi-agent.d.ts +43 -0
- package/dist/types/plugin.d.ts +1 -1
- package/dist/types/provider-runner.d.ts +8 -0
- package/dist/types/provider.d.ts +15 -0
- package/dist/types/runtime-capability-manifest.d.ts +1 -1
- package/dist/types/secret-scrubber.d.ts +15 -0
- package/dist/types/session-markers.d.ts +37 -10
- package/dist/types/session-markers.js +8 -144
- package/dist/types/session-timeline.d.ts +197 -0
- package/dist/types/session-timeline.js +12 -0
- package/dist/types/session.d.ts +172 -11
- package/dist/types/system-prompt.d.ts +27 -0
- package/dist/utils/config-backup.d.ts +9 -1
- package/dist/utils/error.js +3 -4
- package/dist/utils/expect-defined.js +3 -9
- package/dist/utils/heap-watchdog.js +6 -706
- package/dist/utils/index.js +271 -5685
- package/dist/utils/message-invariants.d.ts +4 -1
- package/dist/utils/regex-guard.d.ts +1 -1
- package/dist/utils/sage-output-block.js +5 -42
- package/dist/utils/socket-path.d.ts +1 -1
- package/dist/utils/token-estimate.d.ts +6 -2
- package/dist/utils/wstack-paths.d.ts +2 -0
- package/dist/wiring/proxy-rewrite.d.ts +46 -0
- package/dist/wiring/proxy-rewrite.js +24 -121
- package/dist/worktree/index.js +6 -887
- package/instructions/agents/explore-companion.md +45 -18
- package/instructions/agents/memory-curator.md +34 -22
- package/instructions/coordination/director-preamble.md +12 -7
- package/instructions/coordination/subagent-baseline.md +26 -5
- package/instructions/leader-after-task.md +4 -1
- package/instructions/llm/chimera-review.md +30 -9
- package/instructions/llm/memory-curator.md +31 -0
- package/instructions/sections/tool/delegation-compact.md +2 -0
- package/instructions/sections/tool/delegation-full.md +5 -1
- package/instructions/sections/tool/mailbox-compact.md +5 -1
- package/instructions/sections/tool/mailbox-full.md +3 -0
- package/instructions/sections/tool/session-note-compact.md +3 -0
- package/instructions/sections/tool/session-note-full.md +15 -0
- package/instructions/system-lite.md +9 -4
- package/instructions/system-pro.md +66 -143
- package/instructions/system.md +73 -175
- package/package.json +32 -4
- package/dist/coordination/agents.d.ts +0 -8
- package/dist/coordination/transport.d.ts +0 -2
- package/dist/storage/session-writer/session-writer-summary-tracker.d.ts +0 -28
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
// src/hq/protocol/governance.ts
|
|
2
|
+
var SIGNAL_LEVELS = /* @__PURE__ */ new Set([
|
|
3
|
+
"healthy",
|
|
4
|
+
"notice",
|
|
5
|
+
"warning",
|
|
6
|
+
"unavailable"
|
|
7
|
+
]);
|
|
8
|
+
var SIGNAL_CODES = /* @__PURE__ */ new Set([
|
|
9
|
+
"attachment_broker_healthy",
|
|
10
|
+
"attachment_broker_initializing",
|
|
11
|
+
"attachment_broker_status_unavailable",
|
|
12
|
+
"attachment_broker_degraded",
|
|
13
|
+
"attachment_broker_audit_unhealthy",
|
|
14
|
+
"attachment_broker_revocation_pending",
|
|
15
|
+
"attachment_broker_stopped",
|
|
16
|
+
"broker_missing",
|
|
17
|
+
"broker_invalid",
|
|
18
|
+
"connection_failed",
|
|
19
|
+
"request_rejected",
|
|
20
|
+
"unexpected_response"
|
|
21
|
+
]);
|
|
22
|
+
var OPERATOR_ACTIONS = /* @__PURE__ */ new Set(["none", "observe", "investigate"]);
|
|
23
|
+
var BROKER_STATES = /* @__PURE__ */ new Set(["idle", "active", "retry_wait", "stopped"]);
|
|
24
|
+
var BROKER_HEALTH = /* @__PURE__ */ new Set(["initializing", "healthy", "degraded", "stopped"]);
|
|
25
|
+
function isNonNegativeInteger(value) {
|
|
26
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0;
|
|
27
|
+
}
|
|
28
|
+
function hasOnlyKeys(value, allowed) {
|
|
29
|
+
const allowedKeys = new Set(allowed);
|
|
30
|
+
return Object.keys(value).every((key) => allowedKeys.has(key));
|
|
31
|
+
}
|
|
32
|
+
function isHqGovernanceSnapshotPayload(value) {
|
|
33
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
34
|
+
const payload = value;
|
|
35
|
+
if (!hasOnlyKeys(payload, [
|
|
36
|
+
"schemaVersion",
|
|
37
|
+
"projectId",
|
|
38
|
+
"observedAt",
|
|
39
|
+
"available",
|
|
40
|
+
"signal",
|
|
41
|
+
"daemon",
|
|
42
|
+
"attachmentBroker"
|
|
43
|
+
]) || payload.schemaVersion !== 1 || typeof payload.projectId !== "string" || payload.projectId.length === 0 || typeof payload.observedAt !== "string" || typeof payload.available !== "boolean" || typeof payload.signal !== "object" || payload.signal === null || Array.isArray(payload.signal)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const signal = payload.signal;
|
|
47
|
+
if (!hasOnlyKeys(signal, ["level", "code", "operatorAction", "executionDisposition"]) || !SIGNAL_LEVELS.has(signal.level) || !SIGNAL_CODES.has(signal.code) || !OPERATOR_ACTIONS.has(signal.operatorAction) || signal.executionDisposition !== "continue") {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (payload.available === false && (signal.level !== "unavailable" || payload.daemon !== void 0 || payload.attachmentBroker !== void 0) || payload.available === true && signal.level === "unavailable") {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (payload.daemon !== void 0) {
|
|
54
|
+
if (typeof payload.daemon !== "object" || payload.daemon === null || Array.isArray(payload.daemon)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const daemon = payload.daemon;
|
|
58
|
+
if (!hasOnlyKeys(daemon, ["pid", "startedAt"]) || !isNonNegativeInteger(daemon.pid) || typeof daemon.startedAt !== "string") {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (payload.attachmentBroker !== void 0 && payload.attachmentBroker !== null) {
|
|
63
|
+
if (typeof payload.attachmentBroker !== "object" || Array.isArray(payload.attachmentBroker)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const broker = payload.attachmentBroker;
|
|
67
|
+
if (!hasOnlyKeys(broker, [
|
|
68
|
+
"state",
|
|
69
|
+
"health",
|
|
70
|
+
"consecutiveFailures",
|
|
71
|
+
"pendingRevocations",
|
|
72
|
+
"auditHealthy",
|
|
73
|
+
"expiresAt",
|
|
74
|
+
"nextActionAt"
|
|
75
|
+
]) || !BROKER_STATES.has(broker.state) || !BROKER_HEALTH.has(broker.health) || !isNonNegativeInteger(broker.consecutiveFailures) || !isNonNegativeInteger(broker.pendingRevocations) || typeof broker.auditHealthy !== "boolean" || broker.expiresAt !== void 0 && typeof broker.expiresAt !== "string" || broker.nextActionAt !== void 0 && typeof broker.nextActionAt !== "string") {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/hq/protocol/kanban.ts
|
|
83
|
+
var HQ_KANBAN_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
84
|
+
var MAX_HQ_KANBAN_BOARDS = 250;
|
|
85
|
+
var MAX_HQ_KANBAN_BOARD_BYTES = 75e4;
|
|
86
|
+
function isHqKanbanSnapshotPayload(value) {
|
|
87
|
+
if (typeof value !== "object" || value === null) return false;
|
|
88
|
+
const payload = value;
|
|
89
|
+
if (typeof payload.projectId !== "string" || payload.projectId.length === 0 || typeof payload.generatedAt !== "string" || !Number.isFinite(Date.parse(payload.generatedAt)) || !Array.isArray(payload.boards) || !Array.isArray(payload.tombstones) || payload.boards.length > MAX_HQ_KANBAN_BOARDS || payload.tombstones.length > MAX_HQ_KANBAN_BOARDS || !isOptionalChunkOrdinal(payload.chunkIndex) || !isOptionalChunkOrdinal(payload.chunkCount)) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
const seen = /* @__PURE__ */ new Set();
|
|
93
|
+
for (const item of payload.boards) {
|
|
94
|
+
if (!isBoardRecord(item) || seen.has(item.boardId)) return false;
|
|
95
|
+
seen.add(item.boardId);
|
|
96
|
+
}
|
|
97
|
+
for (const item of payload.tombstones) {
|
|
98
|
+
if (!isTombstone(item) || seen.has(item.boardId)) return false;
|
|
99
|
+
seen.add(item.boardId);
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
function isOptionalChunkOrdinal(value) {
|
|
104
|
+
return value === void 0 || Number.isSafeInteger(value) && value >= 0;
|
|
105
|
+
}
|
|
106
|
+
function isBoardRecord(value) {
|
|
107
|
+
if (typeof value !== "object" || value === null) return false;
|
|
108
|
+
const record = value;
|
|
109
|
+
if (typeof record.boardId !== "string" || !HQ_KANBAN_ID_PATTERN.test(record.boardId) || typeof record.revision !== "number" || !Number.isSafeInteger(record.revision) || record.revision < 0 || typeof record.updatedAt !== "string" || !Number.isFinite(Date.parse(record.updatedAt)) || typeof record.board !== "object" || record.board === null || Array.isArray(record.board)) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const board = record.board;
|
|
113
|
+
if (board.id !== record.boardId) return false;
|
|
114
|
+
try {
|
|
115
|
+
return new TextEncoder().encode(JSON.stringify(board)).byteLength <= MAX_HQ_KANBAN_BOARD_BYTES;
|
|
116
|
+
} catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function isTombstone(value) {
|
|
121
|
+
if (typeof value !== "object" || value === null) return false;
|
|
122
|
+
const record = value;
|
|
123
|
+
return typeof record.boardId === "string" && HQ_KANBAN_ID_PATTERN.test(record.boardId) && typeof record.revision === "number" && Number.isSafeInteger(record.revision) && record.revision >= 0 && typeof record.deletedAt === "string" && Number.isFinite(Date.parse(record.deletedAt));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/hq/protocol/peer.ts
|
|
127
|
+
var HQ_PEER_REHYDRATE_REASONS = /* @__PURE__ */ new Set([
|
|
128
|
+
"graceful",
|
|
129
|
+
"crash",
|
|
130
|
+
"heartbeat-timeout",
|
|
131
|
+
"auth-revoked"
|
|
132
|
+
]);
|
|
133
|
+
var HQ_PEER_REHYDRATE_HINT_MAX_CHARS = 280;
|
|
134
|
+
var HQ_BROWSER_PEER_RESUME_CLIENT_ID = "__hq_peer__";
|
|
135
|
+
function isStringOrUndefined(x) {
|
|
136
|
+
return x === void 0 || typeof x === "string";
|
|
137
|
+
}
|
|
138
|
+
function isHqPeerRehydratePayload(x) {
|
|
139
|
+
if (typeof x !== "object" || x === null || Array.isArray(x)) return false;
|
|
140
|
+
const v = x;
|
|
141
|
+
if (typeof v.projectId !== "string" || v.projectId.length === 0) return false;
|
|
142
|
+
if (typeof v.machineId !== "string" || v.machineId.length === 0) return false;
|
|
143
|
+
if (typeof v.leaderClientId !== "string" || v.leaderClientId.length === 0) return false;
|
|
144
|
+
if (typeof v.previousLeaderHandle !== "string" || v.previousLeaderHandle.length === 0) return false;
|
|
145
|
+
if (typeof v.reason !== "string" || !HQ_PEER_REHYDRATE_REASONS.has(v.reason)) return false;
|
|
146
|
+
if (typeof v.detectedAt !== "string" || !Number.isFinite(Date.parse(v.detectedAt))) return false;
|
|
147
|
+
if (!isStringOrUndefined(v.rehydrateHint)) return false;
|
|
148
|
+
if (v.rehydrateHint !== void 0 && v.rehydrateHint.length > HQ_PEER_REHYDRATE_HINT_MAX_CHARS) return false;
|
|
149
|
+
if (!isStringOrUndefined(v.rehydrateCommandId)) return false;
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
function isHqPeerLostPayload(x) {
|
|
153
|
+
if (typeof x !== "object" || x === null || Array.isArray(x)) return false;
|
|
154
|
+
const v = x;
|
|
155
|
+
if (typeof v.projectId !== "string" || v.projectId.length === 0) return false;
|
|
156
|
+
if (typeof v.machineId !== "string" || v.machineId.length === 0) return false;
|
|
157
|
+
if (typeof v.leaderClientId !== "string" || v.leaderClientId.length === 0) return false;
|
|
158
|
+
if (typeof v.previousLeaderHandle !== "string" || v.previousLeaderHandle.length === 0) return false;
|
|
159
|
+
if (typeof v.reason !== "string" || !HQ_PEER_REHYDRATE_REASONS.has(v.reason)) return false;
|
|
160
|
+
if (typeof v.detectedAt !== "string" || !Number.isFinite(Date.parse(v.detectedAt))) return false;
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/hq/protocol/envelope.ts
|
|
165
|
+
var HQ_PROTOCOL_VERSION = 1;
|
|
166
|
+
|
|
167
|
+
// src/hq/protocol/core.ts
|
|
168
|
+
var KNOWN_HQ_CLIENT_FRAME_TYPES = /* @__PURE__ */ new Set([
|
|
169
|
+
"client.hello",
|
|
170
|
+
"client.event",
|
|
171
|
+
"client.command_poll",
|
|
172
|
+
"client.command_ack",
|
|
173
|
+
"client.resume",
|
|
174
|
+
"client.event_poll"
|
|
175
|
+
]);
|
|
176
|
+
var HQ_CLIENT_KINDS = /* @__PURE__ */ new Set([
|
|
177
|
+
"tui",
|
|
178
|
+
"repl",
|
|
179
|
+
"webui",
|
|
180
|
+
"cli",
|
|
181
|
+
"mailbox",
|
|
182
|
+
"unknown"
|
|
183
|
+
]);
|
|
184
|
+
var HQ_WORKSPACE_KINDS = /* @__PURE__ */ new Set(["git", "directory", "unknown"]);
|
|
185
|
+
var HQ_CLIENT_CAPABILITIES = /* @__PURE__ */ new Set([
|
|
186
|
+
"telemetry.publish",
|
|
187
|
+
"session.summary",
|
|
188
|
+
"fleet.summary",
|
|
189
|
+
"mailbox.summary",
|
|
190
|
+
"mailbox.serve",
|
|
191
|
+
"control.receive"
|
|
192
|
+
]);
|
|
193
|
+
var HQ_COMMAND_ACK_STATUSES = /* @__PURE__ */ new Set([
|
|
194
|
+
"accepted",
|
|
195
|
+
"completed",
|
|
196
|
+
"failed",
|
|
197
|
+
"rejected"
|
|
198
|
+
]);
|
|
199
|
+
function hasStringType(x) {
|
|
200
|
+
return typeof x === "object" && x !== null && typeof x.type === "string";
|
|
201
|
+
}
|
|
202
|
+
function isHqClientIdentity(x) {
|
|
203
|
+
if (typeof x !== "object" || x === null) return false;
|
|
204
|
+
const v = x;
|
|
205
|
+
return typeof v.clientId === "string" && typeof v.kind === "string" && HQ_CLIENT_KINDS.has(v.kind) && typeof v.machineId === "string" && typeof v.startedAt === "string";
|
|
206
|
+
}
|
|
207
|
+
function isHqProjectIdentity(x) {
|
|
208
|
+
if (typeof x !== "object" || x === null) return false;
|
|
209
|
+
const v = x;
|
|
210
|
+
return typeof v.projectId === "string" && typeof v.projectRoot === "string" && typeof v.projectName === "string" && typeof v.machineId === "string" && typeof v.workspaceKind === "string" && HQ_WORKSPACE_KINDS.has(v.workspaceKind);
|
|
211
|
+
}
|
|
212
|
+
function isHqRedactionPolicy(x) {
|
|
213
|
+
if (typeof x !== "object" || x === null) return false;
|
|
214
|
+
const v = x;
|
|
215
|
+
return typeof v.rawContent === "boolean" && (v.toolArgs === "none" || v.toolArgs === "summary" || v.toolArgs === "redacted" || v.toolArgs === "full") && (v.paths === "none" || v.paths === "project-relative" || v.paths === "redacted" || v.paths === "full");
|
|
216
|
+
}
|
|
217
|
+
function isHqClientHelloPayload(x) {
|
|
218
|
+
if (typeof x !== "object" || x === null) return false;
|
|
219
|
+
const v = x;
|
|
220
|
+
return typeof v.protocolVersion === "number" && isHqClientIdentity(v.client) && isHqProjectIdentity(v.project) && Array.isArray(v.capabilities) && v.capabilities.every(
|
|
221
|
+
(capability) => typeof capability === "string" && HQ_CLIENT_CAPABILITIES.has(capability)
|
|
222
|
+
) && (v.redactionPolicy === void 0 || isHqRedactionPolicy(v.redactionPolicy));
|
|
223
|
+
}
|
|
224
|
+
function isHqEventEnvelope(x) {
|
|
225
|
+
if (typeof x !== "object" || x === null) return false;
|
|
226
|
+
const v = x;
|
|
227
|
+
return typeof v.id === "string" && typeof v.type === "string" && v.schemaVersion === HQ_PROTOCOL_VERSION && typeof v.timestamp === "string" && typeof v.clientId === "string" && typeof v.projectId === "string" && Number.isSafeInteger(v.seq) && v.seq >= 0 && Object.hasOwn(v, "payload");
|
|
228
|
+
}
|
|
229
|
+
function isHqClientCommandPollMessage(x) {
|
|
230
|
+
if (typeof x !== "object" || x === null) return false;
|
|
231
|
+
const v = x;
|
|
232
|
+
return typeof v.clientId === "string" && typeof v.projectId === "string" && (v.afterCommandId === void 0 || typeof v.afterCommandId === "string") && (v.limit === void 0 || Number.isSafeInteger(v.limit) && v.limit > 0 && v.limit <= 200);
|
|
233
|
+
}
|
|
234
|
+
function isHqClientCommandAckMessage(x) {
|
|
235
|
+
if (typeof x !== "object" || x === null) return false;
|
|
236
|
+
const v = x;
|
|
237
|
+
return typeof v.clientId === "string" && typeof v.projectId === "string" && typeof v.commandId === "string" && typeof v.status === "string" && HQ_COMMAND_ACK_STATUSES.has(v.status) && (v.message === void 0 || typeof v.message === "string");
|
|
238
|
+
}
|
|
239
|
+
function isHqClientResumeMessage(x) {
|
|
240
|
+
if (typeof x !== "object" || x === null) return false;
|
|
241
|
+
const v = x;
|
|
242
|
+
return typeof v.type === "string" && v.type === "client.resume" && Number.isSafeInteger(v.lastSeqSeen) && v.lastSeqSeen >= 0 && (v.clientId === void 0 || typeof v.clientId === "string") && (v.projectId === void 0 || typeof v.projectId === "string");
|
|
243
|
+
}
|
|
244
|
+
function parseHqFrame(raw) {
|
|
245
|
+
let parsed;
|
|
246
|
+
try {
|
|
247
|
+
parsed = JSON.parse(typeof raw === "string" ? raw : raw.toString("utf8"));
|
|
248
|
+
} catch {
|
|
249
|
+
return { ok: false, reason: "invalid-json" };
|
|
250
|
+
}
|
|
251
|
+
if (!hasStringType(parsed)) {
|
|
252
|
+
return { ok: false, reason: "malformed" };
|
|
253
|
+
}
|
|
254
|
+
const obj = parsed;
|
|
255
|
+
if (!KNOWN_HQ_CLIENT_FRAME_TYPES.has(obj.type)) {
|
|
256
|
+
return { ok: false, reason: "unknown-type" };
|
|
257
|
+
}
|
|
258
|
+
switch (obj.type) {
|
|
259
|
+
case "client.hello":
|
|
260
|
+
if (!isHqClientHelloPayload(obj.payload)) {
|
|
261
|
+
return { ok: false, reason: "malformed" };
|
|
262
|
+
}
|
|
263
|
+
return { ok: true, frame: { type: "client.hello", payload: obj.payload } };
|
|
264
|
+
case "client.event":
|
|
265
|
+
if (!isHqEventEnvelope(obj.event)) {
|
|
266
|
+
return { ok: false, reason: "malformed" };
|
|
267
|
+
}
|
|
268
|
+
return { ok: true, frame: { type: "client.event", event: obj.event } };
|
|
269
|
+
case "client.command_poll":
|
|
270
|
+
if (!isHqClientCommandPollMessage(obj)) {
|
|
271
|
+
return { ok: false, reason: "malformed" };
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
ok: true,
|
|
275
|
+
frame: {
|
|
276
|
+
type: "client.command_poll",
|
|
277
|
+
clientId: obj.clientId,
|
|
278
|
+
projectId: obj.projectId,
|
|
279
|
+
...typeof obj.afterCommandId === "string" ? { afterCommandId: obj.afterCommandId } : {},
|
|
280
|
+
...typeof obj.limit === "number" ? { limit: obj.limit } : {}
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
case "client.command_ack":
|
|
284
|
+
if (!isHqClientCommandAckMessage(obj)) {
|
|
285
|
+
return { ok: false, reason: "malformed" };
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
ok: true,
|
|
289
|
+
frame: {
|
|
290
|
+
type: "client.command_ack",
|
|
291
|
+
clientId: obj.clientId,
|
|
292
|
+
projectId: obj.projectId,
|
|
293
|
+
commandId: obj.commandId,
|
|
294
|
+
status: obj.status,
|
|
295
|
+
...typeof obj.message === "string" ? { message: obj.message } : {}
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
case "client.resume":
|
|
299
|
+
if (!isHqClientResumeMessage(obj)) {
|
|
300
|
+
return { ok: false, reason: "malformed" };
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
ok: true,
|
|
304
|
+
frame: {
|
|
305
|
+
type: "client.resume",
|
|
306
|
+
lastSeqSeen: obj.lastSeqSeen,
|
|
307
|
+
...typeof obj.clientId === "string" ? { clientId: obj.clientId } : {},
|
|
308
|
+
...typeof obj.projectId === "string" ? { projectId: obj.projectId } : {}
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
default: {
|
|
312
|
+
const _exhaustive = obj.type;
|
|
313
|
+
return _exhaustive;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
var KNOWN_HQ_EVENT_PAYLOAD_TYPES = /* @__PURE__ */ new Set([
|
|
318
|
+
"mailbox.snapshot",
|
|
319
|
+
"mailbox.event",
|
|
320
|
+
"kanban.snapshot",
|
|
321
|
+
"session.snapshot",
|
|
322
|
+
"session.transcript",
|
|
323
|
+
"session.ended",
|
|
324
|
+
"fleet.snapshot",
|
|
325
|
+
"fleet.event",
|
|
326
|
+
"brain.event",
|
|
327
|
+
"worktree.event",
|
|
328
|
+
"tool.started",
|
|
329
|
+
"tool.completed",
|
|
330
|
+
"session.usage",
|
|
331
|
+
"client.heartbeat",
|
|
332
|
+
"mcp.health.snapshot",
|
|
333
|
+
"mcp.operation",
|
|
334
|
+
"governance.snapshot",
|
|
335
|
+
"peer.rehydrate",
|
|
336
|
+
"peer.lost"
|
|
337
|
+
]);
|
|
338
|
+
function isHqMcpLatencySummary(x) {
|
|
339
|
+
if (typeof x !== "object" || x === null) return false;
|
|
340
|
+
const v = x;
|
|
341
|
+
return typeof v.count === "number" && (v.lastMs === void 0 || typeof v.lastMs === "number") && (v.minMs === void 0 || typeof v.minMs === "number") && (v.maxMs === void 0 || typeof v.maxMs === "number") && (v.p50Ms === void 0 || typeof v.p50Ms === "number") && (v.p95Ms === void 0 || typeof v.p95Ms === "number");
|
|
342
|
+
}
|
|
343
|
+
function isHqMcpFailureCounts(x) {
|
|
344
|
+
if (typeof x !== "object" || x === null) return false;
|
|
345
|
+
const v = x;
|
|
346
|
+
return typeof v.transport === "number" && typeof v.protocol === "number" && typeof v.tool === "number";
|
|
347
|
+
}
|
|
348
|
+
function isHqMcpHealthCheck(x) {
|
|
349
|
+
if (typeof x !== "object" || x === null) return false;
|
|
350
|
+
const v = x;
|
|
351
|
+
return typeof v.name === "string" && typeof v.passed === "boolean" && (v.value === void 0 || typeof v.value === "number") && (v.threshold === void 0 || typeof v.threshold === "number");
|
|
352
|
+
}
|
|
353
|
+
var HQ_MCP_HEALTH_STATES = /* @__PURE__ */ new Set([
|
|
354
|
+
"disabled",
|
|
355
|
+
"dormant",
|
|
356
|
+
"connecting",
|
|
357
|
+
"healthy",
|
|
358
|
+
"degraded",
|
|
359
|
+
"failed"
|
|
360
|
+
]);
|
|
361
|
+
var HQ_MCP_CONNECTION_STATES = /* @__PURE__ */ new Set([
|
|
362
|
+
"idle",
|
|
363
|
+
"dormant",
|
|
364
|
+
"connecting",
|
|
365
|
+
"connected",
|
|
366
|
+
"reconnecting",
|
|
367
|
+
"disconnected",
|
|
368
|
+
"failed"
|
|
369
|
+
]);
|
|
370
|
+
function isHqMcpServerHealth(x) {
|
|
371
|
+
if (typeof x !== "object" || x === null) return false;
|
|
372
|
+
const v = x;
|
|
373
|
+
return typeof v.name === "string" && typeof v.projectId === "string" && typeof v.clientId === "string" && typeof v.connectionState === "string" && HQ_MCP_CONNECTION_STATES.has(v.connectionState) && typeof v.healthState === "string" && HQ_MCP_HEALTH_STATES.has(v.healthState) && (v.lastSuccessAt === void 0 || typeof v.lastSuccessAt === "string") && (v.lastFailureAt === void 0 || typeof v.lastFailureAt === "string") && (v.lastFailureKind === void 0 || v.lastFailureKind === "transport" || v.lastFailureKind === "protocol" || v.lastFailureKind === "tool") && typeof v.consecutiveFailures === "number" && isHqMcpFailureCounts(v.failures) && typeof v.reconnectCount === "number" && typeof v.wakeCount === "number" && typeof v.sleepCount === "number" && typeof v.restartCount === "number" && isHqMcpLatencySummary(v.connectionLatency) && isHqMcpLatencySummary(v.discoveryLatency) && isHqMcpLatencySummary(v.callLatency) && typeof v.inFlightCalls === "number" && typeof v.peakInFlightCalls === "number" && Array.isArray(v.healthChecks) && v.healthChecks.every(isHqMcpHealthCheck);
|
|
374
|
+
}
|
|
375
|
+
function isHqMcpHealthSnapshotPayload(x) {
|
|
376
|
+
if (typeof x !== "object" || x === null) return false;
|
|
377
|
+
const v = x;
|
|
378
|
+
return Array.isArray(v.servers) && v.servers.every(isHqMcpServerHealth);
|
|
379
|
+
}
|
|
380
|
+
function isHqMcpOperationPayload(x) {
|
|
381
|
+
if (typeof x !== "object" || x === null) return false;
|
|
382
|
+
const v = x;
|
|
383
|
+
return typeof v.operation === "object" && v.operation !== null && Array.isArray(v.servers) && v.servers.every(isHqMcpServerHealth);
|
|
384
|
+
}
|
|
385
|
+
function isHqMailboxMessageSummary(x) {
|
|
386
|
+
if (typeof x !== "object" || x === null) return false;
|
|
387
|
+
const v = x;
|
|
388
|
+
return typeof v.messageId === "string" && typeof v.from === "string" && typeof v.to === "string" && typeof v.subject === "string" && typeof v.priority === "string" && typeof v.timestamp === "string" && typeof v.completed === "boolean" && typeof v.hasBody === "boolean";
|
|
389
|
+
}
|
|
390
|
+
function isHqMailboxAgentSummary(x) {
|
|
391
|
+
if (typeof x !== "object" || x === null) return false;
|
|
392
|
+
const v = x;
|
|
393
|
+
return typeof v.agentId === "string" && typeof v.name === "string" && typeof v.sessionId === "string" && typeof v.status === "string" && typeof v.iterations === "number" && typeof v.toolCalls === "number" && typeof v.lastActivityAt === "string" && typeof v.lastSeenAt === "string" && typeof v.online === "boolean";
|
|
394
|
+
}
|
|
395
|
+
function isHqMailboxSnapshotPayload(x) {
|
|
396
|
+
if (typeof x !== "object" || x === null) return false;
|
|
397
|
+
const v = x;
|
|
398
|
+
if (typeof v.mailboxId !== "string" || v.scope !== "project" && v.scope !== "global" || !Array.isArray(v.messages) || !Array.isArray(v.agents) || typeof v.totals !== "object" || v.totals === null) {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
const totals = v.totals;
|
|
402
|
+
if (typeof totals.messages !== "number" || typeof totals.unread !== "number" || typeof totals.incomplete !== "number" || typeof totals.highPriority !== "number" || typeof totals.onlineAgents !== "number") {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
for (const message of v.messages) {
|
|
406
|
+
if (!isHqMailboxMessageSummary(message)) return false;
|
|
407
|
+
}
|
|
408
|
+
for (const agent of v.agents) {
|
|
409
|
+
if (!isHqMailboxAgentSummary(agent)) return false;
|
|
410
|
+
}
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
var HQ_MAILBOX_EVENT_ACTIONS = /* @__PURE__ */ new Set([
|
|
414
|
+
"message.sent",
|
|
415
|
+
"message.read",
|
|
416
|
+
"message.completed",
|
|
417
|
+
"message.updated",
|
|
418
|
+
"agent.registered",
|
|
419
|
+
"agent.heartbeat",
|
|
420
|
+
"agent.offline",
|
|
421
|
+
"agent.deregistered"
|
|
422
|
+
]);
|
|
423
|
+
function isHqMailboxEventPayload(x) {
|
|
424
|
+
if (typeof x !== "object" || x === null) return false;
|
|
425
|
+
const v = x;
|
|
426
|
+
if (typeof v.mailboxId !== "string") return false;
|
|
427
|
+
if (typeof v.action !== "string" || !HQ_MAILBOX_EVENT_ACTIONS.has(v.action)) return false;
|
|
428
|
+
if (v.message !== void 0 && !isHqMailboxMessageSummary(v.message)) return false;
|
|
429
|
+
if (v.agent !== void 0 && !isHqMailboxAgentSummary(v.agent)) return false;
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
var HQ_SESSION_AGENT_STATUSES = /* @__PURE__ */ new Set([
|
|
433
|
+
"idle",
|
|
434
|
+
"running",
|
|
435
|
+
"streaming",
|
|
436
|
+
"waiting_user",
|
|
437
|
+
"error"
|
|
438
|
+
]);
|
|
439
|
+
function isHqSessionAgentSummary(x) {
|
|
440
|
+
if (typeof x !== "object" || x === null) return false;
|
|
441
|
+
const v = x;
|
|
442
|
+
return typeof v.id === "string" && typeof v.name === "string" && typeof v.status === "string" && HQ_SESSION_AGENT_STATUSES.has(v.status) && typeof v.iterations === "number" && typeof v.toolCalls === "number" && typeof v.lastActivityAt === "string";
|
|
443
|
+
}
|
|
444
|
+
var HQ_SESSION_STATUSES = /* @__PURE__ */ new Set(["active", "idle", "closing", "stale"]);
|
|
445
|
+
function isHqSessionSnapshotPayload(x) {
|
|
446
|
+
if (typeof x !== "object" || x === null) return false;
|
|
447
|
+
const v = x;
|
|
448
|
+
if (typeof v.sessionId !== "string" || typeof v.clientKind !== "string" || typeof v.machineId !== "string" || typeof v.projectId !== "string" || typeof v.projectName !== "string" || typeof v.projectRoot !== "string" || typeof v.status !== "string" || !HQ_SESSION_STATUSES.has(v.status) || typeof v.startedAt !== "string" || typeof v.lastActivityAt !== "string" || typeof v.agentCount !== "number" || !Array.isArray(v.agents)) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
for (const agent of v.agents) {
|
|
452
|
+
if (!isHqSessionAgentSummary(agent)) return false;
|
|
453
|
+
}
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
var HQ_TRANSCRIPT_ROLES = /* @__PURE__ */ new Set([
|
|
457
|
+
"user",
|
|
458
|
+
"assistant",
|
|
459
|
+
"thinking",
|
|
460
|
+
"tool",
|
|
461
|
+
"system",
|
|
462
|
+
"error"
|
|
463
|
+
]);
|
|
464
|
+
function isHqTranscriptEntry(x) {
|
|
465
|
+
if (typeof x !== "object" || x === null) return false;
|
|
466
|
+
const v = x;
|
|
467
|
+
return typeof v.ts === "string" && typeof v.role === "string" && HQ_TRANSCRIPT_ROLES.has(v.role) && typeof v.text === "string";
|
|
468
|
+
}
|
|
469
|
+
function isHqTranscriptAppendPayload(x) {
|
|
470
|
+
if (typeof x !== "object" || x === null) return false;
|
|
471
|
+
const v = x;
|
|
472
|
+
if (typeof v.sessionId !== "string" || typeof v.fromSeq !== "number" || !Array.isArray(v.entries)) {
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
for (const entry of v.entries) {
|
|
476
|
+
if (!isHqTranscriptEntry(entry)) return false;
|
|
477
|
+
}
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
function isHqSessionEndedPayload(x) {
|
|
481
|
+
if (typeof x !== "object" || x === null) return false;
|
|
482
|
+
const v = x;
|
|
483
|
+
return typeof v.sessionId === "string" && typeof v.endedAt === "string";
|
|
484
|
+
}
|
|
485
|
+
var HQ_FLEET_SUBAGENT_STATUS = /* @__PURE__ */ new Set([
|
|
486
|
+
"pending",
|
|
487
|
+
"running",
|
|
488
|
+
"idle",
|
|
489
|
+
"completed",
|
|
490
|
+
"failed",
|
|
491
|
+
"stopped"
|
|
492
|
+
]);
|
|
493
|
+
function isHqSubagentSummary(x) {
|
|
494
|
+
if (typeof x !== "object" || x === null) return false;
|
|
495
|
+
const v = x;
|
|
496
|
+
return typeof v.subagentId === "string" && typeof v.status === "string" && HQ_FLEET_SUBAGENT_STATUS.has(v.status);
|
|
497
|
+
}
|
|
498
|
+
function isOptionalFiniteNumber(x) {
|
|
499
|
+
return x === void 0 || typeof x === "number" && Number.isFinite(x);
|
|
500
|
+
}
|
|
501
|
+
function isHqFleetSnapshotPayload(x) {
|
|
502
|
+
if (typeof x !== "object" || x === null) return false;
|
|
503
|
+
const v = x;
|
|
504
|
+
if (typeof v.runId !== "string" || typeof v.activeSubagents !== "number" || typeof v.queuedTasks !== "number" || typeof v.completedTasks !== "number" || typeof v.failedTasks !== "number" || !Array.isArray(v.subagents)) {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
for (const s of v.subagents) {
|
|
508
|
+
if (!isHqSubagentSummary(s)) return false;
|
|
509
|
+
}
|
|
510
|
+
if (!isOptionalFiniteNumber(v.maxConcurrent)) return false;
|
|
511
|
+
if (!isOptionalFiniteNumber(v.maxSpawns)) return false;
|
|
512
|
+
if (!isOptionalFiniteNumber(v.usedSpawns)) return false;
|
|
513
|
+
if (!isOptionalFiniteNumber(v.remainingSpawns)) return false;
|
|
514
|
+
if (!isOptionalFiniteNumber(v.checkpointMaxSpawns)) return false;
|
|
515
|
+
if (v.effectiveSource !== void 0 && typeof v.effectiveSource !== "string") return false;
|
|
516
|
+
if (v.ceilingMismatch !== void 0 && typeof v.ceilingMismatch !== "boolean") return false;
|
|
517
|
+
return true;
|
|
518
|
+
}
|
|
519
|
+
function isHqFleetEventPayload(x) {
|
|
520
|
+
if (typeof x !== "object" || x === null) return false;
|
|
521
|
+
const v = x;
|
|
522
|
+
return typeof v.runId === "string" && typeof v.event === "string";
|
|
523
|
+
}
|
|
524
|
+
var HQ_BRAIN_EVENT_KINDS = /* @__PURE__ */ new Set([
|
|
525
|
+
"decision_requested",
|
|
526
|
+
"decision_answered",
|
|
527
|
+
"decision_ask_human",
|
|
528
|
+
"human_answered",
|
|
529
|
+
"decision_denied",
|
|
530
|
+
"intervention"
|
|
531
|
+
]);
|
|
532
|
+
function isHqBrainEventPayload(x) {
|
|
533
|
+
if (typeof x !== "object" || x === null) return false;
|
|
534
|
+
const v = x;
|
|
535
|
+
if (typeof v.kind !== "string" || !HQ_BRAIN_EVENT_KINDS.has(v.kind)) return false;
|
|
536
|
+
if (typeof v.at !== "number") return false;
|
|
537
|
+
return true;
|
|
538
|
+
}
|
|
539
|
+
var HQ_WORKTREE_EVENT_KINDS = /* @__PURE__ */ new Set([
|
|
540
|
+
"allocated",
|
|
541
|
+
"committed",
|
|
542
|
+
"merged",
|
|
543
|
+
"conflict",
|
|
544
|
+
"released",
|
|
545
|
+
"failed"
|
|
546
|
+
]);
|
|
547
|
+
function isHqWorktreeEventPayload(x) {
|
|
548
|
+
if (typeof x !== "object" || x === null) return false;
|
|
549
|
+
const v = x;
|
|
550
|
+
if (typeof v.kind !== "string" || !HQ_WORKTREE_EVENT_KINDS.has(v.kind)) return false;
|
|
551
|
+
if (typeof v.handleId !== "string" || typeof v.ownerId !== "string") return false;
|
|
552
|
+
return true;
|
|
553
|
+
}
|
|
554
|
+
function isHqToolStartedPayload(x) {
|
|
555
|
+
if (typeof x !== "object" || x === null) return false;
|
|
556
|
+
const v = x;
|
|
557
|
+
return typeof v.toolName === "string";
|
|
558
|
+
}
|
|
559
|
+
function isHqToolCompletedPayload(x) {
|
|
560
|
+
if (typeof x !== "object" || x === null) return false;
|
|
561
|
+
const v = x;
|
|
562
|
+
return typeof v.toolName === "string" && typeof v.status === "string" && typeof v.durationMs === "number";
|
|
563
|
+
}
|
|
564
|
+
function isHqUsagePayload(x) {
|
|
565
|
+
if (typeof x !== "object" || x === null) return false;
|
|
566
|
+
return !Array.isArray(x);
|
|
567
|
+
}
|
|
568
|
+
function isHqClientHeartbeatPayload(x) {
|
|
569
|
+
if (typeof x !== "object" || x === null || Array.isArray(x)) return false;
|
|
570
|
+
const v = x;
|
|
571
|
+
return typeof v.uptimeMs === "number" && (v.activeSessionId === void 0 || typeof v.activeSessionId === "string") && (v.activeRunId === void 0 || typeof v.activeRunId === "string") && typeof v.status === "string" && (v.status === "active" || v.status === "idle" || v.status === "stale" || v.status === "error") && (v.activeSubagents === void 0 || typeof v.activeSubagents === "number") && (v.queuedTasks === void 0 || typeof v.queuedTasks === "number");
|
|
572
|
+
}
|
|
573
|
+
function parseHqEventPayload(eventType, payload) {
|
|
574
|
+
if (!KNOWN_HQ_EVENT_PAYLOAD_TYPES.has(eventType)) {
|
|
575
|
+
return { ok: true, payload };
|
|
576
|
+
}
|
|
577
|
+
switch (eventType) {
|
|
578
|
+
case "mailbox.snapshot":
|
|
579
|
+
return isHqMailboxSnapshotPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
580
|
+
case "mailbox.event":
|
|
581
|
+
return isHqMailboxEventPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
582
|
+
case "kanban.snapshot":
|
|
583
|
+
return isHqKanbanSnapshotPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
584
|
+
case "session.snapshot":
|
|
585
|
+
return isHqSessionSnapshotPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
586
|
+
case "session.transcript":
|
|
587
|
+
return isHqTranscriptAppendPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
588
|
+
case "session.ended":
|
|
589
|
+
return isHqSessionEndedPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
590
|
+
case "fleet.snapshot":
|
|
591
|
+
return isHqFleetSnapshotPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
592
|
+
case "fleet.event":
|
|
593
|
+
return isHqFleetEventPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
594
|
+
case "brain.event":
|
|
595
|
+
return isHqBrainEventPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
596
|
+
case "worktree.event":
|
|
597
|
+
return isHqWorktreeEventPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
598
|
+
case "tool.started":
|
|
599
|
+
return isHqToolStartedPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
600
|
+
case "tool.completed":
|
|
601
|
+
return isHqToolCompletedPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
602
|
+
case "session.usage":
|
|
603
|
+
return isHqUsagePayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
604
|
+
case "client.heartbeat":
|
|
605
|
+
return isHqClientHeartbeatPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
606
|
+
case "mcp.health.snapshot":
|
|
607
|
+
return isHqMcpHealthSnapshotPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
608
|
+
case "mcp.operation":
|
|
609
|
+
return isHqMcpOperationPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
610
|
+
case "governance.snapshot":
|
|
611
|
+
return isHqGovernanceSnapshotPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
612
|
+
case "peer.rehydrate":
|
|
613
|
+
return isHqPeerRehydratePayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
614
|
+
case "peer.lost":
|
|
615
|
+
return isHqPeerLostPayload(payload) ? { ok: true, payload } : { ok: false, reason: "malformed-payload" };
|
|
616
|
+
default: {
|
|
617
|
+
const _exhaustive = eventType;
|
|
618
|
+
return _exhaustive;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
function createHqEventEnvelope(input) {
|
|
623
|
+
return {
|
|
624
|
+
id: input.id,
|
|
625
|
+
type: input.type,
|
|
626
|
+
schemaVersion: HQ_PROTOCOL_VERSION,
|
|
627
|
+
timestamp: input.timestamp,
|
|
628
|
+
clientId: input.clientId,
|
|
629
|
+
projectId: input.projectId,
|
|
630
|
+
seq: input.seq,
|
|
631
|
+
payload: input.payload,
|
|
632
|
+
...input.sessionId !== void 0 ? { sessionId: input.sessionId } : {},
|
|
633
|
+
...input.runId !== void 0 ? { runId: input.runId } : {}
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// src/hq/protocol/resume.ts
|
|
638
|
+
var HQ_RESUME_GAP_MAX_ENVELOPES = 1e3;
|
|
639
|
+
var HQ_RESUME_GAP_MAX_BYTES = 1048576;
|
|
640
|
+
var HQ_RESUME_GAP_MAX_STALE_MS = 24 * 60 * 60 * 1e3;
|
|
641
|
+
function isHqResumeGapMessage(x) {
|
|
642
|
+
if (typeof x !== "object" || x === null || Array.isArray(x)) return false;
|
|
643
|
+
const v = x;
|
|
644
|
+
if (v.type !== "hq.resume_gap") return false;
|
|
645
|
+
if (!Number.isSafeInteger(v.lastSeqSeen) || v.lastSeqSeen < 0) return false;
|
|
646
|
+
if (!Array.isArray(v.envelopes)) return false;
|
|
647
|
+
if (v.envelopes.length > HQ_RESUME_GAP_MAX_ENVELOPES) return false;
|
|
648
|
+
if (typeof v.truncated !== "boolean") return false;
|
|
649
|
+
return true;
|
|
650
|
+
}
|
|
651
|
+
function isHqResumeRejectMessage(x) {
|
|
652
|
+
if (typeof x !== "object" || x === null || Array.isArray(x)) return false;
|
|
653
|
+
const v = x;
|
|
654
|
+
if (v.type !== "hq.resume_reject") return false;
|
|
655
|
+
if (v.reason !== "gap_too_large" && v.reason !== "last_seen_too_old" && v.reason !== "log_unavailable") {
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
if (typeof v.detectedAt !== "string" || !Number.isFinite(Date.parse(v.detectedAt))) return false;
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// src/hq/protocol/tool.ts
|
|
663
|
+
var DEFAULT_HQ_REDACTION_POLICY = {
|
|
664
|
+
rawContent: true,
|
|
665
|
+
toolArgs: "full",
|
|
666
|
+
paths: "full"
|
|
667
|
+
};
|
|
668
|
+
var HQ_TRANSCRIPT_TEXT_CAP = 16e3;
|
|
669
|
+
|
|
670
|
+
export {
|
|
671
|
+
isHqGovernanceSnapshotPayload,
|
|
672
|
+
MAX_HQ_KANBAN_BOARD_BYTES,
|
|
673
|
+
isHqKanbanSnapshotPayload,
|
|
674
|
+
HQ_PEER_REHYDRATE_REASONS,
|
|
675
|
+
HQ_PEER_REHYDRATE_HINT_MAX_CHARS,
|
|
676
|
+
HQ_BROWSER_PEER_RESUME_CLIENT_ID,
|
|
677
|
+
isHqPeerRehydratePayload,
|
|
678
|
+
isHqPeerLostPayload,
|
|
679
|
+
HQ_PROTOCOL_VERSION,
|
|
680
|
+
parseHqFrame,
|
|
681
|
+
parseHqEventPayload,
|
|
682
|
+
createHqEventEnvelope,
|
|
683
|
+
HQ_RESUME_GAP_MAX_ENVELOPES,
|
|
684
|
+
HQ_RESUME_GAP_MAX_BYTES,
|
|
685
|
+
HQ_RESUME_GAP_MAX_STALE_MS,
|
|
686
|
+
isHqResumeGapMessage,
|
|
687
|
+
isHqResumeRejectMessage,
|
|
688
|
+
DEFAULT_HQ_REDACTION_POLICY,
|
|
689
|
+
HQ_TRANSCRIPT_TEXT_CAP
|
|
690
|
+
};
|
|
691
|
+
//# sourceMappingURL=chunk-Z2IJUO45.js.map
|