adaptive-bitmask 1.0.0 → 2.0.5
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 +220 -255
- package/dist/ai/index.d.mts +16 -1
- package/dist/ai/index.d.ts +16 -1
- package/dist/ai/index.js +102 -6
- package/dist/ai/index.mjs +53 -5
- package/dist/{chunk-ZWEXRT33.mjs → chunk-QICJNGMQ.mjs} +53 -2
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +378 -0
- package/dist/cli/index.mjs +355 -0
- package/dist/{coordinator-Df48t6yJ.d.mts → coordinator-CqBBHhXv.d.mts} +6 -1
- package/dist/{coordinator-Df48t6yJ.d.ts → coordinator-CqBBHhXv.d.ts} +6 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +53 -2
- package/dist/index.mjs +1 -1
- package/package.json +17 -4
package/dist/ai/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SchemaManager, C as Coordinator, A as Arbiter,
|
|
1
|
+
import { S as SchemaManager, C as Coordinator, A as Arbiter, a as CoordinatorConfig, b as ArbiterConfig, D as Decision, c as ArbiterResult } from '../coordinator-CqBBHhXv.mjs';
|
|
2
2
|
import * as ai from 'ai';
|
|
3
3
|
import { LanguageModelV1Middleware } from 'ai';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -10,6 +10,13 @@ import { z } from 'zod';
|
|
|
10
10
|
* that AI SDK tools and middleware can reference.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
interface SessionLog {
|
|
14
|
+
timestamp: number;
|
|
15
|
+
agentId: string;
|
|
16
|
+
type: 'observation' | 'decision' | 'thinking' | 'system';
|
|
17
|
+
content: string;
|
|
18
|
+
metadata?: any;
|
|
19
|
+
}
|
|
13
20
|
interface CoordinationSessionConfig {
|
|
14
21
|
/** Initial feature vocabulary to register. */
|
|
15
22
|
features: string[];
|
|
@@ -21,6 +28,8 @@ interface CoordinationSessionConfig {
|
|
|
21
28
|
coordinatorConfig?: Partial<CoordinatorConfig>;
|
|
22
29
|
/** Arbiter configuration overrides. */
|
|
23
30
|
arbiterConfig?: Partial<ArbiterConfig>;
|
|
31
|
+
/** Optional callback for telemetry/logs. */
|
|
32
|
+
onLog?: (log: SessionLog) => void;
|
|
24
33
|
}
|
|
25
34
|
interface ReportResult {
|
|
26
35
|
accepted: boolean;
|
|
@@ -37,14 +46,20 @@ declare class CoordinationSession {
|
|
|
37
46
|
readonly schema: SchemaManager;
|
|
38
47
|
readonly coordinator: Coordinator;
|
|
39
48
|
readonly arbiter: Arbiter;
|
|
49
|
+
private readonly _onLog?;
|
|
40
50
|
private readonly _agentIds;
|
|
41
51
|
constructor(config: CoordinationSessionConfig);
|
|
52
|
+
private _log;
|
|
42
53
|
/** Deterministic agent ID: FNV-1a hash of name → uint32. */
|
|
43
54
|
agentId(name: string): number;
|
|
55
|
+
/** Log internal "thinking" or reasoning from an agent. */
|
|
56
|
+
logThinking(agentName: string, content: string, metadata?: any): void;
|
|
44
57
|
/** Start a new coordination round. Clears the coordinator buffer. */
|
|
45
58
|
startRound(): void;
|
|
46
59
|
/** Encode features + create message + receive in one call. */
|
|
47
60
|
report(agentName: string, features: string[]): ReportResult;
|
|
61
|
+
/** Aggregate current buffer without clearing it. */
|
|
62
|
+
peek(): DecisionResult;
|
|
48
63
|
/** Aggregate current buffer + score via arbiter. */
|
|
49
64
|
decide(): DecisionResult;
|
|
50
65
|
}
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SchemaManager, C as Coordinator, A as Arbiter,
|
|
1
|
+
import { S as SchemaManager, C as Coordinator, A as Arbiter, a as CoordinatorConfig, b as ArbiterConfig, D as Decision, c as ArbiterResult } from '../coordinator-CqBBHhXv.js';
|
|
2
2
|
import * as ai from 'ai';
|
|
3
3
|
import { LanguageModelV1Middleware } from 'ai';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -10,6 +10,13 @@ import { z } from 'zod';
|
|
|
10
10
|
* that AI SDK tools and middleware can reference.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
interface SessionLog {
|
|
14
|
+
timestamp: number;
|
|
15
|
+
agentId: string;
|
|
16
|
+
type: 'observation' | 'decision' | 'thinking' | 'system';
|
|
17
|
+
content: string;
|
|
18
|
+
metadata?: any;
|
|
19
|
+
}
|
|
13
20
|
interface CoordinationSessionConfig {
|
|
14
21
|
/** Initial feature vocabulary to register. */
|
|
15
22
|
features: string[];
|
|
@@ -21,6 +28,8 @@ interface CoordinationSessionConfig {
|
|
|
21
28
|
coordinatorConfig?: Partial<CoordinatorConfig>;
|
|
22
29
|
/** Arbiter configuration overrides. */
|
|
23
30
|
arbiterConfig?: Partial<ArbiterConfig>;
|
|
31
|
+
/** Optional callback for telemetry/logs. */
|
|
32
|
+
onLog?: (log: SessionLog) => void;
|
|
24
33
|
}
|
|
25
34
|
interface ReportResult {
|
|
26
35
|
accepted: boolean;
|
|
@@ -37,14 +46,20 @@ declare class CoordinationSession {
|
|
|
37
46
|
readonly schema: SchemaManager;
|
|
38
47
|
readonly coordinator: Coordinator;
|
|
39
48
|
readonly arbiter: Arbiter;
|
|
49
|
+
private readonly _onLog?;
|
|
40
50
|
private readonly _agentIds;
|
|
41
51
|
constructor(config: CoordinationSessionConfig);
|
|
52
|
+
private _log;
|
|
42
53
|
/** Deterministic agent ID: FNV-1a hash of name → uint32. */
|
|
43
54
|
agentId(name: string): number;
|
|
55
|
+
/** Log internal "thinking" or reasoning from an agent. */
|
|
56
|
+
logThinking(agentName: string, content: string, metadata?: any): void;
|
|
44
57
|
/** Start a new coordination round. Clears the coordinator buffer. */
|
|
45
58
|
startRound(): void;
|
|
46
59
|
/** Encode features + create message + receive in one call. */
|
|
47
60
|
report(agentName: string, features: string[]): ReportResult;
|
|
61
|
+
/** Aggregate current buffer without clearing it. */
|
|
62
|
+
peek(): DecisionResult;
|
|
48
63
|
/** Aggregate current buffer + score via arbiter. */
|
|
49
64
|
decide(): DecisionResult;
|
|
50
65
|
}
|
package/dist/ai/index.js
CHANGED
|
@@ -665,6 +665,52 @@ var Coordinator = class {
|
|
|
665
665
|
}
|
|
666
666
|
return accepted;
|
|
667
667
|
}
|
|
668
|
+
/**
|
|
669
|
+
* Peek at current consensus state without clearing the buffer.
|
|
670
|
+
* Useful for mid-round status queries by AI agents.
|
|
671
|
+
*/
|
|
672
|
+
peekAggregate() {
|
|
673
|
+
if (this._buffer.length === 0) {
|
|
674
|
+
return {
|
|
675
|
+
aggregatedMask: 0n,
|
|
676
|
+
confidence: /* @__PURE__ */ new Map(),
|
|
677
|
+
messageCount: 0,
|
|
678
|
+
uniqueAgents: 0,
|
|
679
|
+
staleMessages: 0,
|
|
680
|
+
droppedStaleMessages: this._droppedStaleMessages,
|
|
681
|
+
aggregationTimeUs: 0
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
const t0 = performance.now();
|
|
685
|
+
let aggregated = 0n;
|
|
686
|
+
const bitVotes = /* @__PURE__ */ new Map();
|
|
687
|
+
const uniqueAgents = /* @__PURE__ */ new Set();
|
|
688
|
+
let staleCount = 0;
|
|
689
|
+
for (const msg of this._buffer) {
|
|
690
|
+
uniqueAgents.add(msg.agentId);
|
|
691
|
+
if (this._schemaVersion !== void 0 && msg.schemaVersion !== this._schemaVersion) {
|
|
692
|
+
staleCount++;
|
|
693
|
+
}
|
|
694
|
+
aggregated |= msg.mask;
|
|
695
|
+
forEachSetBit(msg.mask, (bit) => {
|
|
696
|
+
bitVotes.set(bit, (bitVotes.get(bit) ?? 0) + 1);
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
const confidence = /* @__PURE__ */ new Map();
|
|
700
|
+
for (const [bit, count] of bitVotes) {
|
|
701
|
+
confidence.set(bit, count / this._buffer.length);
|
|
702
|
+
}
|
|
703
|
+
const elapsed = (performance.now() - t0) * 1e3;
|
|
704
|
+
return {
|
|
705
|
+
aggregatedMask: aggregated,
|
|
706
|
+
confidence,
|
|
707
|
+
messageCount: this._buffer.length,
|
|
708
|
+
uniqueAgents: uniqueAgents.size,
|
|
709
|
+
staleMessages: staleCount,
|
|
710
|
+
droppedStaleMessages: this._droppedStaleMessages,
|
|
711
|
+
aggregationTimeUs: elapsed
|
|
712
|
+
};
|
|
713
|
+
}
|
|
668
714
|
/**
|
|
669
715
|
* Aggregate all buffered messages into a consensus result.
|
|
670
716
|
* Clears the buffer after aggregation.
|
|
@@ -692,8 +738,6 @@ var Coordinator = class {
|
|
|
692
738
|
}
|
|
693
739
|
const elapsed = (performance.now() - t0) * 1e3;
|
|
694
740
|
this._aggregationCount++;
|
|
695
|
-
this._buffer = [];
|
|
696
|
-
this._seenAgents.clear();
|
|
697
741
|
const result = {
|
|
698
742
|
aggregatedMask: aggregated,
|
|
699
743
|
confidence,
|
|
@@ -703,6 +747,10 @@ var Coordinator = class {
|
|
|
703
747
|
droppedStaleMessages: this._droppedStaleMessages,
|
|
704
748
|
aggregationTimeUs: elapsed
|
|
705
749
|
};
|
|
750
|
+
this._buffer = [];
|
|
751
|
+
this._seenAgents.clear();
|
|
752
|
+
this._roundStartTime = 0;
|
|
753
|
+
this._droppedStaleMessages = 0;
|
|
706
754
|
this._emitTelemetry({ type: "round_aggregated", result });
|
|
707
755
|
return result;
|
|
708
756
|
}
|
|
@@ -980,6 +1028,7 @@ var CoordinationSession = class {
|
|
|
980
1028
|
schema;
|
|
981
1029
|
coordinator;
|
|
982
1030
|
arbiter;
|
|
1031
|
+
_onLog;
|
|
983
1032
|
_agentIds = /* @__PURE__ */ new Map();
|
|
984
1033
|
constructor(config) {
|
|
985
1034
|
this.schema = new SchemaManager({
|
|
@@ -992,6 +1041,11 @@ var CoordinationSession = class {
|
|
|
992
1041
|
schemaVersion: this.schema.version
|
|
993
1042
|
});
|
|
994
1043
|
this.arbiter = new Arbiter(config.arbiterConfig);
|
|
1044
|
+
this._onLog = config.onLog;
|
|
1045
|
+
}
|
|
1046
|
+
_log(log) {
|
|
1047
|
+
const fullLog = { ...log, timestamp: Date.now() };
|
|
1048
|
+
this._onLog?.(fullLog);
|
|
995
1049
|
}
|
|
996
1050
|
/** Deterministic agent ID: FNV-1a hash of name → uint32. */
|
|
997
1051
|
agentId(name) {
|
|
@@ -1006,12 +1060,33 @@ var CoordinationSession = class {
|
|
|
1006
1060
|
this._agentIds.set(name, id);
|
|
1007
1061
|
return id;
|
|
1008
1062
|
}
|
|
1063
|
+
/** Log internal "thinking" or reasoning from an agent. */
|
|
1064
|
+
logThinking(agentName, content, metadata) {
|
|
1065
|
+
this._log({
|
|
1066
|
+
agentId: agentName,
|
|
1067
|
+
type: "thinking",
|
|
1068
|
+
content,
|
|
1069
|
+
metadata
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1009
1072
|
/** Start a new coordination round. Clears the coordinator buffer. */
|
|
1010
1073
|
startRound() {
|
|
1011
1074
|
this.coordinator.startRound();
|
|
1075
|
+
this._log({
|
|
1076
|
+
agentId: "system",
|
|
1077
|
+
type: "system",
|
|
1078
|
+
content: "Started new coordination round"
|
|
1079
|
+
});
|
|
1012
1080
|
}
|
|
1013
1081
|
/** Encode features + create message + receive in one call. */
|
|
1014
1082
|
report(agentName, features) {
|
|
1083
|
+
this._log({
|
|
1084
|
+
agentId: agentName,
|
|
1085
|
+
type: "observation",
|
|
1086
|
+
content: `Reported features: ${features.join(", ")}`,
|
|
1087
|
+
metadata: { features }
|
|
1088
|
+
});
|
|
1089
|
+
this.schema.recordActivations(features);
|
|
1015
1090
|
const { mask, mapped, unmapped } = encode(
|
|
1016
1091
|
features,
|
|
1017
1092
|
this.schema.featureToBit
|
|
@@ -1024,11 +1099,33 @@ var CoordinationSession = class {
|
|
|
1024
1099
|
const accepted = this.coordinator.receive(msg);
|
|
1025
1100
|
return { accepted, mapped, unmapped };
|
|
1026
1101
|
}
|
|
1102
|
+
/** Aggregate current buffer without clearing it. */
|
|
1103
|
+
peek() {
|
|
1104
|
+
const { aggregatedMask, confidence } = this.coordinator.peekAggregate();
|
|
1105
|
+
const aggregatedFeatures = decode(aggregatedMask, this.schema.bitToFeatures);
|
|
1106
|
+
const result = this.arbiter.score(aggregatedMask, confidence);
|
|
1107
|
+
return {
|
|
1108
|
+
decision: result.decision,
|
|
1109
|
+
aggregatedFeatures,
|
|
1110
|
+
confidence,
|
|
1111
|
+
result
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1027
1114
|
/** Aggregate current buffer + score via arbiter. */
|
|
1028
1115
|
decide() {
|
|
1029
1116
|
const { aggregatedMask, confidence } = this.coordinator.aggregate();
|
|
1030
1117
|
const aggregatedFeatures = decode(aggregatedMask, this.schema.bitToFeatures);
|
|
1031
1118
|
const result = this.arbiter.score(aggregatedMask, confidence);
|
|
1119
|
+
this._log({
|
|
1120
|
+
agentId: "system",
|
|
1121
|
+
type: "decision",
|
|
1122
|
+
content: `Final Decision: ${result.decision}`,
|
|
1123
|
+
metadata: {
|
|
1124
|
+
result,
|
|
1125
|
+
aggregatedFeatures,
|
|
1126
|
+
score: result.finalScore
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1032
1129
|
return {
|
|
1033
1130
|
decision: result.decision,
|
|
1034
1131
|
aggregatedFeatures,
|
|
@@ -1061,16 +1158,15 @@ function createCoordinationTools(session) {
|
|
|
1061
1158
|
description: "Query the current aggregated consensus state across all agents.",
|
|
1062
1159
|
parameters: import_zod.z.object({}),
|
|
1063
1160
|
execute: async () => {
|
|
1064
|
-
const {
|
|
1065
|
-
const features = decode(aggregatedMask, session.schema.bitToFeatures);
|
|
1161
|
+
const { aggregatedFeatures, confidence, result } = session.peek();
|
|
1066
1162
|
const confidenceObj = {};
|
|
1067
1163
|
for (const [bit, conf] of confidence) {
|
|
1068
1164
|
confidenceObj[String(bit)] = conf;
|
|
1069
1165
|
}
|
|
1070
1166
|
return {
|
|
1071
|
-
features,
|
|
1167
|
+
features: aggregatedFeatures,
|
|
1072
1168
|
confidence: confidenceObj,
|
|
1073
|
-
agentCount:
|
|
1169
|
+
agentCount: session.coordinator.bufferedCount
|
|
1074
1170
|
};
|
|
1075
1171
|
}
|
|
1076
1172
|
});
|
package/dist/ai/index.mjs
CHANGED
|
@@ -6,13 +6,14 @@ import {
|
|
|
6
6
|
decode,
|
|
7
7
|
encode,
|
|
8
8
|
hasEmergency
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-QICJNGMQ.mjs";
|
|
10
10
|
|
|
11
11
|
// src/ai/session.ts
|
|
12
12
|
var CoordinationSession = class {
|
|
13
13
|
schema;
|
|
14
14
|
coordinator;
|
|
15
15
|
arbiter;
|
|
16
|
+
_onLog;
|
|
16
17
|
_agentIds = /* @__PURE__ */ new Map();
|
|
17
18
|
constructor(config) {
|
|
18
19
|
this.schema = new SchemaManager({
|
|
@@ -25,6 +26,11 @@ var CoordinationSession = class {
|
|
|
25
26
|
schemaVersion: this.schema.version
|
|
26
27
|
});
|
|
27
28
|
this.arbiter = new Arbiter(config.arbiterConfig);
|
|
29
|
+
this._onLog = config.onLog;
|
|
30
|
+
}
|
|
31
|
+
_log(log) {
|
|
32
|
+
const fullLog = { ...log, timestamp: Date.now() };
|
|
33
|
+
this._onLog?.(fullLog);
|
|
28
34
|
}
|
|
29
35
|
/** Deterministic agent ID: FNV-1a hash of name → uint32. */
|
|
30
36
|
agentId(name) {
|
|
@@ -39,12 +45,33 @@ var CoordinationSession = class {
|
|
|
39
45
|
this._agentIds.set(name, id);
|
|
40
46
|
return id;
|
|
41
47
|
}
|
|
48
|
+
/** Log internal "thinking" or reasoning from an agent. */
|
|
49
|
+
logThinking(agentName, content, metadata) {
|
|
50
|
+
this._log({
|
|
51
|
+
agentId: agentName,
|
|
52
|
+
type: "thinking",
|
|
53
|
+
content,
|
|
54
|
+
metadata
|
|
55
|
+
});
|
|
56
|
+
}
|
|
42
57
|
/** Start a new coordination round. Clears the coordinator buffer. */
|
|
43
58
|
startRound() {
|
|
44
59
|
this.coordinator.startRound();
|
|
60
|
+
this._log({
|
|
61
|
+
agentId: "system",
|
|
62
|
+
type: "system",
|
|
63
|
+
content: "Started new coordination round"
|
|
64
|
+
});
|
|
45
65
|
}
|
|
46
66
|
/** Encode features + create message + receive in one call. */
|
|
47
67
|
report(agentName, features) {
|
|
68
|
+
this._log({
|
|
69
|
+
agentId: agentName,
|
|
70
|
+
type: "observation",
|
|
71
|
+
content: `Reported features: ${features.join(", ")}`,
|
|
72
|
+
metadata: { features }
|
|
73
|
+
});
|
|
74
|
+
this.schema.recordActivations(features);
|
|
48
75
|
const { mask, mapped, unmapped } = encode(
|
|
49
76
|
features,
|
|
50
77
|
this.schema.featureToBit
|
|
@@ -57,11 +84,33 @@ var CoordinationSession = class {
|
|
|
57
84
|
const accepted = this.coordinator.receive(msg);
|
|
58
85
|
return { accepted, mapped, unmapped };
|
|
59
86
|
}
|
|
87
|
+
/** Aggregate current buffer without clearing it. */
|
|
88
|
+
peek() {
|
|
89
|
+
const { aggregatedMask, confidence } = this.coordinator.peekAggregate();
|
|
90
|
+
const aggregatedFeatures = decode(aggregatedMask, this.schema.bitToFeatures);
|
|
91
|
+
const result = this.arbiter.score(aggregatedMask, confidence);
|
|
92
|
+
return {
|
|
93
|
+
decision: result.decision,
|
|
94
|
+
aggregatedFeatures,
|
|
95
|
+
confidence,
|
|
96
|
+
result
|
|
97
|
+
};
|
|
98
|
+
}
|
|
60
99
|
/** Aggregate current buffer + score via arbiter. */
|
|
61
100
|
decide() {
|
|
62
101
|
const { aggregatedMask, confidence } = this.coordinator.aggregate();
|
|
63
102
|
const aggregatedFeatures = decode(aggregatedMask, this.schema.bitToFeatures);
|
|
64
103
|
const result = this.arbiter.score(aggregatedMask, confidence);
|
|
104
|
+
this._log({
|
|
105
|
+
agentId: "system",
|
|
106
|
+
type: "decision",
|
|
107
|
+
content: `Final Decision: ${result.decision}`,
|
|
108
|
+
metadata: {
|
|
109
|
+
result,
|
|
110
|
+
aggregatedFeatures,
|
|
111
|
+
score: result.finalScore
|
|
112
|
+
}
|
|
113
|
+
});
|
|
65
114
|
return {
|
|
66
115
|
decision: result.decision,
|
|
67
116
|
aggregatedFeatures,
|
|
@@ -94,16 +143,15 @@ function createCoordinationTools(session) {
|
|
|
94
143
|
description: "Query the current aggregated consensus state across all agents.",
|
|
95
144
|
parameters: z.object({}),
|
|
96
145
|
execute: async () => {
|
|
97
|
-
const {
|
|
98
|
-
const features = decode(aggregatedMask, session.schema.bitToFeatures);
|
|
146
|
+
const { aggregatedFeatures, confidence, result } = session.peek();
|
|
99
147
|
const confidenceObj = {};
|
|
100
148
|
for (const [bit, conf] of confidence) {
|
|
101
149
|
confidenceObj[String(bit)] = conf;
|
|
102
150
|
}
|
|
103
151
|
return {
|
|
104
|
-
features,
|
|
152
|
+
features: aggregatedFeatures,
|
|
105
153
|
confidence: confidenceObj,
|
|
106
|
-
agentCount:
|
|
154
|
+
agentCount: session.coordinator.bufferedCount
|
|
107
155
|
};
|
|
108
156
|
}
|
|
109
157
|
});
|
|
@@ -1928,6 +1928,52 @@ var Coordinator = class {
|
|
|
1928
1928
|
}
|
|
1929
1929
|
return accepted;
|
|
1930
1930
|
}
|
|
1931
|
+
/**
|
|
1932
|
+
* Peek at current consensus state without clearing the buffer.
|
|
1933
|
+
* Useful for mid-round status queries by AI agents.
|
|
1934
|
+
*/
|
|
1935
|
+
peekAggregate() {
|
|
1936
|
+
if (this._buffer.length === 0) {
|
|
1937
|
+
return {
|
|
1938
|
+
aggregatedMask: 0n,
|
|
1939
|
+
confidence: /* @__PURE__ */ new Map(),
|
|
1940
|
+
messageCount: 0,
|
|
1941
|
+
uniqueAgents: 0,
|
|
1942
|
+
staleMessages: 0,
|
|
1943
|
+
droppedStaleMessages: this._droppedStaleMessages,
|
|
1944
|
+
aggregationTimeUs: 0
|
|
1945
|
+
};
|
|
1946
|
+
}
|
|
1947
|
+
const t0 = performance.now();
|
|
1948
|
+
let aggregated = 0n;
|
|
1949
|
+
const bitVotes = /* @__PURE__ */ new Map();
|
|
1950
|
+
const uniqueAgents = /* @__PURE__ */ new Set();
|
|
1951
|
+
let staleCount = 0;
|
|
1952
|
+
for (const msg of this._buffer) {
|
|
1953
|
+
uniqueAgents.add(msg.agentId);
|
|
1954
|
+
if (this._schemaVersion !== void 0 && msg.schemaVersion !== this._schemaVersion) {
|
|
1955
|
+
staleCount++;
|
|
1956
|
+
}
|
|
1957
|
+
aggregated |= msg.mask;
|
|
1958
|
+
forEachSetBit(msg.mask, (bit) => {
|
|
1959
|
+
bitVotes.set(bit, (bitVotes.get(bit) ?? 0) + 1);
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1962
|
+
const confidence = /* @__PURE__ */ new Map();
|
|
1963
|
+
for (const [bit, count] of bitVotes) {
|
|
1964
|
+
confidence.set(bit, count / this._buffer.length);
|
|
1965
|
+
}
|
|
1966
|
+
const elapsed = (performance.now() - t0) * 1e3;
|
|
1967
|
+
return {
|
|
1968
|
+
aggregatedMask: aggregated,
|
|
1969
|
+
confidence,
|
|
1970
|
+
messageCount: this._buffer.length,
|
|
1971
|
+
uniqueAgents: uniqueAgents.size,
|
|
1972
|
+
staleMessages: staleCount,
|
|
1973
|
+
droppedStaleMessages: this._droppedStaleMessages,
|
|
1974
|
+
aggregationTimeUs: elapsed
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1931
1977
|
/**
|
|
1932
1978
|
* Aggregate all buffered messages into a consensus result.
|
|
1933
1979
|
* Clears the buffer after aggregation.
|
|
@@ -1955,8 +2001,6 @@ var Coordinator = class {
|
|
|
1955
2001
|
}
|
|
1956
2002
|
const elapsed = (performance.now() - t0) * 1e3;
|
|
1957
2003
|
this._aggregationCount++;
|
|
1958
|
-
this._buffer = [];
|
|
1959
|
-
this._seenAgents.clear();
|
|
1960
2004
|
const result = {
|
|
1961
2005
|
aggregatedMask: aggregated,
|
|
1962
2006
|
confidence,
|
|
@@ -1966,6 +2010,10 @@ var Coordinator = class {
|
|
|
1966
2010
|
droppedStaleMessages: this._droppedStaleMessages,
|
|
1967
2011
|
aggregationTimeUs: elapsed
|
|
1968
2012
|
};
|
|
2013
|
+
this._buffer = [];
|
|
2014
|
+
this._seenAgents.clear();
|
|
2015
|
+
this._roundStartTime = 0;
|
|
2016
|
+
this._droppedStaleMessages = 0;
|
|
1969
2017
|
this._emitTelemetry({ type: "round_aggregated", result });
|
|
1970
2018
|
return result;
|
|
1971
2019
|
}
|
|
@@ -2284,6 +2332,9 @@ var SharedCognition = class {
|
|
|
2284
2332
|
*/
|
|
2285
2333
|
processSwarmTick(agentObservations) {
|
|
2286
2334
|
const startMs = performance.now();
|
|
2335
|
+
if (this.schema.activeFeatureCount >= 50) {
|
|
2336
|
+
this.schema.prune();
|
|
2337
|
+
}
|
|
2287
2338
|
if (this.autoRegister) {
|
|
2288
2339
|
const uniqueFeatures = /* @__PURE__ */ new Set();
|
|
2289
2340
|
for (const obs of agentObservations) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|