pi-fabric 0.92.18 → 0.92.19
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/chunks/{chunk-RNOPHITP.js → chunk-H6DDV6E2.js} +180 -24
- package/dist/chunks/chunk-H6DDV6E2.js.map +7 -0
- package/dist/entropy/compiler.d.ts +8 -0
- package/dist/entropy/compiler.d.ts.map +1 -1
- package/dist/entropy/index.js +9 -1
- package/dist/entropy/meter.d.ts +10 -0
- package/dist/entropy/meter.d.ts.map +1 -1
- package/dist/entropy/pool.d.ts +5 -0
- package/dist/entropy/pool.d.ts.map +1 -1
- package/dist/entropy/sessions.d.ts +12 -1
- package/dist/entropy/sessions.d.ts.map +1 -1
- package/dist/fabric-runtime-state.js +7 -1
- package/dist/fabric-runtime-state.js.map +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -9
- package/dist/index.js.map +2 -2
- package/dist/speculation/stream-tap.d.ts.map +1 -1
- package/dist/worker/model-control.d.ts.map +1 -1
- package/dist/worker/model-control.js +0 -1
- package/dist/worker/model-control.js.map +2 -2
- package/dist/worker.js +3 -9
- package/dist/worker.js.map +2 -2
- package/docs/agents.md +2 -2
- package/docs/entropy.md +17 -1
- package/package.json +2 -1
- package/dist/chunks/chunk-RNOPHITP.js.map +0 -7
|
@@ -220,6 +220,82 @@ var finalizeMeasure = (input, state) => {
|
|
|
220
220
|
refs: sortedRefs
|
|
221
221
|
};
|
|
222
222
|
};
|
|
223
|
+
var mergeCounts = (target, source) => {
|
|
224
|
+
for (const [key, count] of source) target.set(key, (target.get(key) ?? 0) + count);
|
|
225
|
+
};
|
|
226
|
+
var mergeMeasureState = (target, source) => {
|
|
227
|
+
for (const key of Object.keys(source.totals)) {
|
|
228
|
+
target.totals[key] += source.totals[key];
|
|
229
|
+
}
|
|
230
|
+
target.churnPairs += source.churnPairs;
|
|
231
|
+
target.churnSum += source.churnSum;
|
|
232
|
+
for (const [ref, acc] of source.refs) {
|
|
233
|
+
const into = accumulatorFor(target, ref);
|
|
234
|
+
for (const key of ["calls", "succeeded", "failed", "churnPairs", "churnSum"]) into[key] += acc[key];
|
|
235
|
+
mergeCounts(into.signatures, acc.signatures);
|
|
236
|
+
mergeCounts(into.stages, acc.stages);
|
|
237
|
+
}
|
|
238
|
+
for (const [task, sequences] of source.taskSequences) {
|
|
239
|
+
let into = target.taskSequences.get(task);
|
|
240
|
+
if (!into) target.taskSequences.set(task, into = /* @__PURE__ */ new Map());
|
|
241
|
+
mergeCounts(into, sequences);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
var SessionEntropyMeter = class {
|
|
245
|
+
#windows = /* @__PURE__ */ new Map();
|
|
246
|
+
async measure(windows, input) {
|
|
247
|
+
const reportInput = { ...input, traces: [] };
|
|
248
|
+
const combined = createMeasureState(reportInput);
|
|
249
|
+
const models = /* @__PURE__ */ new Map();
|
|
250
|
+
for (const window of windows) {
|
|
251
|
+
let cached = this.#windows.get(window.file);
|
|
252
|
+
if (cached?.traces !== window.traces) {
|
|
253
|
+
const append = cached && cached.traces.length <= window.traces.length && cached.traces.every((trace, index) => trace === window.traces[index]);
|
|
254
|
+
if (!append) cached = { traces: [], state: createMeasureState({ traces: [] }), models: /* @__PURE__ */ new Map() };
|
|
255
|
+
const entry2 = cached;
|
|
256
|
+
this.#windows.delete(window.file);
|
|
257
|
+
for (let index = entry2.traces.length; index < window.traces.length; index++) {
|
|
258
|
+
const trace = window.traces[index];
|
|
259
|
+
accumulateTrace(entry2.state, trace);
|
|
260
|
+
entry2.state.totals.traces++;
|
|
261
|
+
if (trace.model) {
|
|
262
|
+
let model = entry2.models.get(trace.model);
|
|
263
|
+
if (!model) entry2.models.set(trace.model, model = createMeasureState({ traces: [] }));
|
|
264
|
+
accumulateTrace(model, trace);
|
|
265
|
+
model.totals.traces++;
|
|
266
|
+
}
|
|
267
|
+
if ((index + 1) % COOPERATIVE_TRACE_CHUNK === 0) await yieldToLoop();
|
|
268
|
+
}
|
|
269
|
+
entry2.traces = window.traces;
|
|
270
|
+
}
|
|
271
|
+
const entry = cached;
|
|
272
|
+
this.#windows.delete(window.file);
|
|
273
|
+
this.#windows.set(window.file, entry);
|
|
274
|
+
while (this.#windows.size > 16) this.#windows.delete(this.#windows.keys().next().value);
|
|
275
|
+
mergeMeasureState(combined, entry.state);
|
|
276
|
+
for (const [name, source] of entry.models) {
|
|
277
|
+
let model = models.get(name);
|
|
278
|
+
if (!model) models.set(name, model = createMeasureState(reportInput));
|
|
279
|
+
mergeMeasureState(model, source);
|
|
280
|
+
}
|
|
281
|
+
await yieldToLoop();
|
|
282
|
+
}
|
|
283
|
+
const report = finalizeMeasure(reportInput, combined);
|
|
284
|
+
const byModel = [...models.entries()].sort(([a], [b]) => compareCodeUnits(a, b)).map(([model, state]) => {
|
|
285
|
+
const scoped = finalizeMeasure(reportInput, state);
|
|
286
|
+
return {
|
|
287
|
+
model,
|
|
288
|
+
operations: scoped.totals.operations,
|
|
289
|
+
actionOperations: scoped.totals.actionOperations,
|
|
290
|
+
succeeded: scoped.totals.succeeded,
|
|
291
|
+
invocationRejections: scoped.totals.invocationRejections,
|
|
292
|
+
invocationRejectionsPer1k: scoped.totals.invocationRejectionsPer1k,
|
|
293
|
+
behavioralScore: scoped.behavioralScore
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
return { ...report, byModel };
|
|
297
|
+
}
|
|
298
|
+
};
|
|
223
299
|
var measureOnce = (input) => {
|
|
224
300
|
const state = createMeasureState(input);
|
|
225
301
|
for (const trace of input.traces) accumulateTrace(state, trace);
|
|
@@ -569,26 +645,24 @@ var digestFromIdentityCountsAsync = async (counts) => {
|
|
|
569
645
|
const hash = createHash("sha256");
|
|
570
646
|
hash.update("[");
|
|
571
647
|
let first = true;
|
|
572
|
-
let
|
|
573
|
-
const flush = async () => {
|
|
574
|
-
if (encodedBatch.length === 0) return;
|
|
575
|
-
hash.update(`${first ? "" : ","}${encodedBatch.join(",")}`);
|
|
576
|
-
first = false;
|
|
577
|
-
encodedBatch = [];
|
|
578
|
-
await yieldToLoop2();
|
|
579
|
-
};
|
|
648
|
+
let processed = 0;
|
|
580
649
|
for (const [identity, count] of Object.entries(counts).sort(
|
|
581
650
|
([left], [right]) => compareCodeUnits(left, right)
|
|
582
651
|
)) {
|
|
583
652
|
const encoded = JSON.stringify(identity);
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
653
|
+
const batchSize = Math.max(1, Math.floor(32768 / (encoded.length + 1)));
|
|
654
|
+
for (let remaining = count; remaining > 0; ) {
|
|
655
|
+
const size = Math.min(remaining, batchSize, COOPERATIVE_DIGEST_CHUNK - processed);
|
|
656
|
+
hash.update(`${first ? "" : ","}${encoded}${`,${encoded}`.repeat(size - 1)}`);
|
|
657
|
+
first = false;
|
|
658
|
+
remaining -= size;
|
|
659
|
+
processed += size;
|
|
660
|
+
if (processed >= COOPERATIVE_DIGEST_CHUNK) {
|
|
661
|
+
processed = 0;
|
|
662
|
+
await yieldToLoop2();
|
|
663
|
+
}
|
|
587
664
|
}
|
|
588
665
|
}
|
|
589
|
-
if (encodedBatch.length > 0) {
|
|
590
|
-
hash.update(`${first ? "" : ","}${encodedBatch.join(",")}`);
|
|
591
|
-
}
|
|
592
666
|
hash.update("]");
|
|
593
667
|
return hash.digest("hex");
|
|
594
668
|
};
|
|
@@ -707,7 +781,7 @@ var mergeObservationSummaries = (pool, windows) => {
|
|
|
707
781
|
const entry = working.get(entryId);
|
|
708
782
|
if (entry) enforceValueCap(entry);
|
|
709
783
|
}
|
|
710
|
-
const trackedSession = { file: window.file, digest, counts: fresh };
|
|
784
|
+
const trackedSession = { file: window.file, digest, counts: { ...fresh } };
|
|
711
785
|
if (existing) {
|
|
712
786
|
tracked[existingIndex] = trackedSession;
|
|
713
787
|
} else {
|
|
@@ -739,6 +813,36 @@ var mergeObservationWindow = (pool, windows) => mergeObservationSummaries(
|
|
|
739
813
|
summary: summarizeObservations(window.observations)
|
|
740
814
|
}))
|
|
741
815
|
);
|
|
816
|
+
var SessionObservationCache = class {
|
|
817
|
+
#windows = /* @__PURE__ */ new Map();
|
|
818
|
+
async merge(pool, windows) {
|
|
819
|
+
const summarized = [];
|
|
820
|
+
for (const window of windows) {
|
|
821
|
+
let cached = this.#windows.get(window.file);
|
|
822
|
+
if (cached?.observations !== window.observations) {
|
|
823
|
+
const append = cached && cached.observations.length <= window.observations.length && cached.observations.every((observation, index) => observation === window.observations[index]);
|
|
824
|
+
const counts = append ? { ...cached.counts } : {};
|
|
825
|
+
const digestCounts = append ? { ...cached.digestCounts } : {};
|
|
826
|
+
const start = append ? cached.observations.length : 0;
|
|
827
|
+
for (let index = start; index < window.observations.length; index++) {
|
|
828
|
+
const observation = window.observations[index];
|
|
829
|
+
const identity = observationIdentity(observation);
|
|
830
|
+
counts[identity] = (counts[identity] ?? 0) + (observation.count ?? 1);
|
|
831
|
+
digestCounts[identity] = (digestCounts[identity] ?? 0) + 1;
|
|
832
|
+
if ((index + 1) % COOPERATIVE_OBSERVATION_CHUNK === 0) await yieldToLoop2();
|
|
833
|
+
}
|
|
834
|
+
const digest = append && start === window.observations.length ? cached.summary.digest : await digestFromIdentityCountsAsync(digestCounts);
|
|
835
|
+
cached = { observations: window.observations, counts, digestCounts, summary: { counts, digest } };
|
|
836
|
+
}
|
|
837
|
+
this.#windows.delete(window.file);
|
|
838
|
+
this.#windows.set(window.file, cached);
|
|
839
|
+
while (this.#windows.size > 16) this.#windows.delete(this.#windows.keys().next().value);
|
|
840
|
+
summarized.push({ file: window.file, summary: cached.summary });
|
|
841
|
+
await yieldToLoop2();
|
|
842
|
+
}
|
|
843
|
+
return mergeObservationSummaries(pool, summarized);
|
|
844
|
+
}
|
|
845
|
+
};
|
|
742
846
|
var mergeObservationWindowAsync = async (pool, windows) => {
|
|
743
847
|
const summarized = [];
|
|
744
848
|
for (const window of windows) {
|
|
@@ -986,8 +1090,8 @@ var formatEntropyReviewSignal = (proposal) => {
|
|
|
986
1090
|
return `${proposal.kind} ${proposal.ref}`;
|
|
987
1091
|
};
|
|
988
1092
|
var sortedActions = (surface) => [...surface.actions].sort((a, b) => a.ref < b.ref ? -1 : a.ref > b.ref ? 1 : 0);
|
|
989
|
-
var finishCompile = (input, report, plans) => {
|
|
990
|
-
const review = entropyReviewSignals({ ...input, report });
|
|
1093
|
+
var finishCompile = (input, report, plans, reviewSignals = true) => {
|
|
1094
|
+
const review = reviewSignals ? entropyReviewSignals({ ...input, report }) : [];
|
|
991
1095
|
const previous = input.artifact;
|
|
992
1096
|
const current = previous?.version === COMPILED_SURFACE_VERSION && previous.actions.length === 0 && previous.quarantined.length === 0 && stableJsonHash(previous.normalizations ?? []) === stableJsonHash(plans);
|
|
993
1097
|
if (current || !previous && plans.length === 0) {
|
|
@@ -1009,6 +1113,30 @@ var finishCompile = (input, report, plans) => {
|
|
|
1009
1113
|
};
|
|
1010
1114
|
return { status: "compiled", artifact, report, after: report, proposals: [...proposals, ...review], gate };
|
|
1011
1115
|
};
|
|
1116
|
+
var BackgroundEntropyCompiler = class {
|
|
1117
|
+
#meter = new SessionEntropyMeter();
|
|
1118
|
+
#plans;
|
|
1119
|
+
async compile(input) {
|
|
1120
|
+
const digest = entropySurfaceHash(input.surface);
|
|
1121
|
+
if (this.#plans?.digest !== digest) {
|
|
1122
|
+
const plans2 = [];
|
|
1123
|
+
let processed = 0;
|
|
1124
|
+
for (const action of sortedActions(input.surface)) {
|
|
1125
|
+
const plan = deriveNormalFormPlan(action.ref, action.inputSchema);
|
|
1126
|
+
if (plan && plans2.length < MAX_NORMAL_FORM_PLANS) plans2.push(plan);
|
|
1127
|
+
if (++processed % 32 === 0) await new Promise((resolve) => setImmediate(resolve));
|
|
1128
|
+
}
|
|
1129
|
+
this.#plans = { digest, plans: plans2 };
|
|
1130
|
+
}
|
|
1131
|
+
const plans = this.#plans.plans;
|
|
1132
|
+
const report = await this.#meter.measure(input.windows, {
|
|
1133
|
+
surface: input.surface,
|
|
1134
|
+
...input.repairs ? { repairs: input.repairs } : {},
|
|
1135
|
+
catalogDigest: input.catalogDigest ?? digest
|
|
1136
|
+
});
|
|
1137
|
+
return finishCompile({ ...input, traces: [] }, report, structuredClone(plans), false);
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1012
1140
|
var compileEntropySurface = (input) => {
|
|
1013
1141
|
const report = measureEntropy({ ...input, catalogDigest: input.catalogDigest ?? entropySurfaceHash(input.surface) });
|
|
1014
1142
|
const plans = [];
|
|
@@ -1422,6 +1550,23 @@ var measureSessionCorpus = (input) => {
|
|
|
1422
1550
|
}
|
|
1423
1551
|
return finalizeSessionCorpus(input.files, sessions);
|
|
1424
1552
|
};
|
|
1553
|
+
var BackgroundSessionSelector = class {
|
|
1554
|
+
constructor(scan = machineSessionFilesAsync) {
|
|
1555
|
+
this.scan = scan;
|
|
1556
|
+
}
|
|
1557
|
+
#cached;
|
|
1558
|
+
async select(agentDir, cwd, currentFile) {
|
|
1559
|
+
const cached = this.#cached;
|
|
1560
|
+
let files;
|
|
1561
|
+
if (cached && cached.agentDir === agentDir && cached.cwd === cwd && Date.now() < cached.until) {
|
|
1562
|
+
files = cached.files;
|
|
1563
|
+
} else {
|
|
1564
|
+
files = await this.scan(agentDir, cwd);
|
|
1565
|
+
this.#cached = files.length > 0 ? { agentDir, cwd, files, until: Date.now() + 3e4 } : void 0;
|
|
1566
|
+
}
|
|
1567
|
+
return currentFile ? [currentFile, ...files.filter((file) => file !== currentFile)].slice(0, DEFAULT_SESSION_WINDOW) : [...files];
|
|
1568
|
+
}
|
|
1569
|
+
};
|
|
1425
1570
|
var sessionMetadata = async (file) => {
|
|
1426
1571
|
try {
|
|
1427
1572
|
const entry = await fs2.promises.stat(file);
|
|
@@ -1460,6 +1605,7 @@ var scanSessionRange = async (file, start, end, initialModel) => {
|
|
|
1460
1605
|
}
|
|
1461
1606
|
};
|
|
1462
1607
|
var evidenceWindow = (file, evidence) => ({
|
|
1608
|
+
traceWindows: [{ file, traces: evidence.traces }],
|
|
1463
1609
|
traces: evidence.traces,
|
|
1464
1610
|
valueObservations: evidence.valueObservations,
|
|
1465
1611
|
auditCalls: evidence.auditCalls,
|
|
@@ -1516,20 +1662,24 @@ var readSessionEvidenceAsync = async (file) => {
|
|
|
1516
1662
|
}
|
|
1517
1663
|
return evidenceWindow(file, evidence);
|
|
1518
1664
|
};
|
|
1519
|
-
var sessionWindowEvidenceAsync = async (files) => {
|
|
1665
|
+
var sessionWindowEvidenceAsync = async (files, options = {}) => {
|
|
1520
1666
|
const windows = await mapConcurrent(files, SESSION_READ_CONCURRENCY, readSessionEvidenceAsync);
|
|
1521
1667
|
const traces = [];
|
|
1522
1668
|
const valueObservations = [];
|
|
1523
1669
|
const auditCalls = [];
|
|
1524
1670
|
const observationWindows = [];
|
|
1671
|
+
const traceWindows = [];
|
|
1525
1672
|
for (const window of windows) {
|
|
1526
1673
|
if (!window) continue;
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1674
|
+
if (!options.windowsOnly) {
|
|
1675
|
+
for (const trace of window.traces) traces.push(trace);
|
|
1676
|
+
for (const observation of window.valueObservations) valueObservations.push(observation);
|
|
1677
|
+
for (const call of window.auditCalls) auditCalls.push(call);
|
|
1678
|
+
}
|
|
1530
1679
|
observationWindows.push(...window.observationWindows);
|
|
1680
|
+
traceWindows.push(...window.traceWindows);
|
|
1531
1681
|
}
|
|
1532
|
-
return { traces, valueObservations, auditCalls, observationWindows };
|
|
1682
|
+
return { traces, valueObservations, auditCalls, observationWindows, traceWindows };
|
|
1533
1683
|
};
|
|
1534
1684
|
var measureSessionCorpusAsync = async (input) => {
|
|
1535
1685
|
const windows = await mapConcurrent(
|
|
@@ -1557,6 +1707,7 @@ var sessionWindowEvidence = (files) => {
|
|
|
1557
1707
|
const valueObservations = [];
|
|
1558
1708
|
const auditCalls = [];
|
|
1559
1709
|
const observationWindows = [];
|
|
1710
|
+
const traceWindows = [];
|
|
1560
1711
|
for (const file of files) {
|
|
1561
1712
|
let text;
|
|
1562
1713
|
try {
|
|
@@ -1569,8 +1720,9 @@ var sessionWindowEvidence = (files) => {
|
|
|
1569
1720
|
valueObservations.push(...evidence.valueObservations);
|
|
1570
1721
|
auditCalls.push(...evidence.auditCalls);
|
|
1571
1722
|
observationWindows.push({ file, observations: evidence.valueObservations });
|
|
1723
|
+
traceWindows.push({ file, traces: evidence.traces });
|
|
1572
1724
|
}
|
|
1573
|
-
return { traces, valueObservations, auditCalls, observationWindows };
|
|
1725
|
+
return { traces, valueObservations, auditCalls, observationWindows, traceWindows };
|
|
1574
1726
|
};
|
|
1575
1727
|
|
|
1576
1728
|
// src/entropy/trial.ts
|
|
@@ -1677,6 +1829,7 @@ export {
|
|
|
1677
1829
|
entropyAuditCallsFromSessionJsonl,
|
|
1678
1830
|
entropyRepairRows,
|
|
1679
1831
|
entropyReportHash,
|
|
1832
|
+
SessionEntropyMeter,
|
|
1680
1833
|
measureEntropy,
|
|
1681
1834
|
measureEntropyAsync,
|
|
1682
1835
|
projectSessionFiles,
|
|
@@ -1684,6 +1837,7 @@ export {
|
|
|
1684
1837
|
projectSessionFilesAsync,
|
|
1685
1838
|
machineSessionFilesAsync,
|
|
1686
1839
|
measureSessionCorpus,
|
|
1840
|
+
BackgroundSessionSelector,
|
|
1687
1841
|
sessionWindowEvidenceAsync,
|
|
1688
1842
|
measureSessionCorpusAsync,
|
|
1689
1843
|
sessionWindowEvidence,
|
|
@@ -1694,6 +1848,7 @@ export {
|
|
|
1694
1848
|
AUTO_APPLY_PROPOSAL_KINDS,
|
|
1695
1849
|
entropyReviewSignals,
|
|
1696
1850
|
formatEntropyReviewSignal,
|
|
1851
|
+
BackgroundEntropyCompiler,
|
|
1697
1852
|
compileEntropySurface,
|
|
1698
1853
|
compileEntropySurfaceAsync,
|
|
1699
1854
|
OBSERVATION_POOL_VERSION,
|
|
@@ -1703,6 +1858,7 @@ export {
|
|
|
1703
1858
|
observationIdentity,
|
|
1704
1859
|
observationWindowDigest,
|
|
1705
1860
|
mergeObservationWindow,
|
|
1861
|
+
SessionObservationCache,
|
|
1706
1862
|
mergeObservationWindowAsync,
|
|
1707
1863
|
poolToValueObservations,
|
|
1708
1864
|
observationPoolDirectory,
|
|
@@ -1717,4 +1873,4 @@ export {
|
|
|
1717
1873
|
formatEntropyCompileNotice,
|
|
1718
1874
|
runEntropyTrial
|
|
1719
1875
|
};
|
|
1720
|
-
//# sourceMappingURL=chunk-
|
|
1876
|
+
//# sourceMappingURL=chunk-H6DDV6E2.js.map
|