@atlaswork/atlascode 0.1.130 → 0.1.131
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.
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* 才释放,杜绝 close 竞态下槽位早释的限额绕过)。
|
|
32
32
|
*/
|
|
33
33
|
import type { WebSessionEvent } from './contract.js';
|
|
34
|
-
import type { CursorLedger } from './cursorLedger.js';
|
|
34
|
+
import type { CursorLedger, CursorBinding } from './cursorLedger.js';
|
|
35
35
|
import type { SessionStoreAdapter } from './sessionStoreAdapter.js';
|
|
36
36
|
import { type ProjectionEngineDeps, type ProjectionSourceMessage } from './projection.js';
|
|
37
37
|
/** 投影消息源结构面(engine TranscriptMessage 的结构超集镜像,pack 域零引擎导入)。 */
|
|
@@ -62,6 +62,16 @@ export interface FollowDeps {
|
|
|
62
62
|
limits: FollowLimits;
|
|
63
63
|
signal?: AbortSignal;
|
|
64
64
|
ledger: CursorLedger;
|
|
65
|
+
/**
|
|
66
|
+
* W-FC-1 修形 2(工单 docs/2026-11-28-wfc1-ledger-evict-ticket.md §3 格 2):
|
|
67
|
+
* 活跃 cursor 被账本压力淘汰的 sink 注册/注销面(runtime 持注册表,
|
|
68
|
+
* ledger onActiveEvict 分发后即删)。issue 成功后注册、setTerminal 兜底
|
|
69
|
+
* 注销。inline 类型——零新 export(红线:零新 wire 形/export)。
|
|
70
|
+
*/
|
|
71
|
+
evictRouter: {
|
|
72
|
+
register: (token: string, sink: (token: string, binding: CursorBinding) => void) => void;
|
|
73
|
+
unregister: (token: string) => void;
|
|
74
|
+
};
|
|
65
75
|
/** 引擎 loader 全量基线面(显式 filePath;呈批书 §7.3 钉死形,注入缝)。 */
|
|
66
76
|
loadFull: (filePath: string) => Promise<{
|
|
67
77
|
messages: Map<string, ProjectionSourceMessage>;
|
|
@@ -1160,6 +1160,9 @@ class CursorLedger {
|
|
|
1160
1160
|
this.onActiveEvict = onActiveEvict;
|
|
1161
1161
|
}
|
|
1162
1162
|
issue(binding, payloadBytes = 0) {
|
|
1163
|
+
if (payloadBytes > this.maxPayloadBytes) {
|
|
1164
|
+
throw new WebSessionError("resourceLimit", `ledger payload exceeds cap (${payloadBytes} > ${this.maxPayloadBytes} bytes)`);
|
|
1165
|
+
}
|
|
1163
1166
|
this.evictForInsert(payloadBytes);
|
|
1164
1167
|
const token = randomUUID();
|
|
1165
1168
|
this.entries.set(token, {
|
|
@@ -1495,10 +1498,20 @@ function createFollowSubscription(deps) {
|
|
|
1495
1498
|
terminalRank = rank;
|
|
1496
1499
|
running = false;
|
|
1497
1500
|
disarmLease();
|
|
1498
|
-
for (const t of issuedTokens)
|
|
1501
|
+
for (const t of issuedTokens) {
|
|
1499
1502
|
ledger.unpin(t);
|
|
1503
|
+
deps.evictRouter.unregister(t);
|
|
1504
|
+
}
|
|
1500
1505
|
notify();
|
|
1501
1506
|
}
|
|
1507
|
+
function handleActiveEvict(token, binding) {
|
|
1508
|
+
queueData({
|
|
1509
|
+
...envelope(deps),
|
|
1510
|
+
kind: "resetRequired",
|
|
1511
|
+
generation: binding.generation,
|
|
1512
|
+
reason: "active cursor evicted (ledger pressure)"
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1502
1515
|
function queueData(ev) {
|
|
1503
1516
|
if (terminalEvent || finished)
|
|
1504
1517
|
return;
|
|
@@ -1600,19 +1613,29 @@ function createFollowSubscription(deps) {
|
|
|
1600
1613
|
setTerminal(errorEvent("resourceLimit", `projection exceeds limit (${bytes} bytes)`));
|
|
1601
1614
|
return false;
|
|
1602
1615
|
}
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1616
|
+
let cursor;
|
|
1617
|
+
try {
|
|
1618
|
+
cursor = ledger.issue({
|
|
1619
|
+
v: 1,
|
|
1620
|
+
productId: deps.productId,
|
|
1621
|
+
scopeId: deps.scopeId,
|
|
1622
|
+
sessionId: deps.sessionId,
|
|
1623
|
+
baselineId,
|
|
1624
|
+
generation,
|
|
1625
|
+
revision,
|
|
1626
|
+
byteOffset: offset,
|
|
1627
|
+
ino: anchorIno
|
|
1628
|
+
}, bytes);
|
|
1629
|
+
} catch (e) {
|
|
1630
|
+
if (e instanceof WebSessionError && e.code === "resourceLimit") {
|
|
1631
|
+
setTerminal(errorEvent("resourceLimit", e.message));
|
|
1632
|
+
return false;
|
|
1633
|
+
}
|
|
1634
|
+
throw e;
|
|
1635
|
+
}
|
|
1614
1636
|
ledger.pin(cursor);
|
|
1615
1637
|
issuedTokens.push(cursor);
|
|
1638
|
+
deps.evictRouter.register(cursor, handleActiveEvict);
|
|
1616
1639
|
queueData({
|
|
1617
1640
|
...envelope(deps),
|
|
1618
1641
|
kind: "baseline",
|
|
@@ -1715,19 +1738,29 @@ function createFollowSubscription(deps) {
|
|
|
1715
1738
|
return;
|
|
1716
1739
|
}
|
|
1717
1740
|
revision++;
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1741
|
+
let cursor;
|
|
1742
|
+
try {
|
|
1743
|
+
cursor = ledger.issue({
|
|
1744
|
+
v: 1,
|
|
1745
|
+
productId: deps.productId,
|
|
1746
|
+
scopeId: deps.scopeId,
|
|
1747
|
+
sessionId: deps.sessionId,
|
|
1748
|
+
baselineId,
|
|
1749
|
+
generation,
|
|
1750
|
+
revision,
|
|
1751
|
+
byteOffset: offset,
|
|
1752
|
+
ino: anchorIno
|
|
1753
|
+
}, bytes);
|
|
1754
|
+
} catch (e) {
|
|
1755
|
+
if (e instanceof WebSessionError && e.code === "resourceLimit") {
|
|
1756
|
+
setTerminal(errorEvent("resourceLimit", e.message));
|
|
1757
|
+
return;
|
|
1758
|
+
}
|
|
1759
|
+
throw e;
|
|
1760
|
+
}
|
|
1729
1761
|
ledger.pin(cursor);
|
|
1730
1762
|
issuedTokens.push(cursor);
|
|
1763
|
+
deps.evictRouter.register(cursor, handleActiveEvict);
|
|
1731
1764
|
queueData({
|
|
1732
1765
|
...envelope(deps),
|
|
1733
1766
|
kind: "replacement",
|
|
@@ -2689,7 +2722,12 @@ function createReadonlySessionRuntime(options) {
|
|
|
2689
2722
|
let state = "idle";
|
|
2690
2723
|
const subscriptions = new Set;
|
|
2691
2724
|
let activeReads = 0;
|
|
2692
|
-
const
|
|
2725
|
+
const evictSinks = new Map;
|
|
2726
|
+
const cursorLedger = new CursorLedger(L.ledgerCapacity, L.cursorTtlMs, L.ledgerPayloadBytes, (token, binding) => {
|
|
2727
|
+
const sink = evictSinks.get(token);
|
|
2728
|
+
evictSinks.delete(token);
|
|
2729
|
+
sink?.(token, binding);
|
|
2730
|
+
});
|
|
2693
2731
|
function assertStarted(operation) {
|
|
2694
2732
|
if (state === "idle") {
|
|
2695
2733
|
throw new WebSessionError("closed", "not started");
|
|
@@ -2955,6 +2993,14 @@ function createReadonlySessionRuntime(options) {
|
|
|
2955
2993
|
},
|
|
2956
2994
|
signal,
|
|
2957
2995
|
ledger: cursorLedger,
|
|
2996
|
+
evictRouter: {
|
|
2997
|
+
register: (token, sink) => {
|
|
2998
|
+
evictSinks.set(token, sink);
|
|
2999
|
+
},
|
|
3000
|
+
unregister: (token) => {
|
|
3001
|
+
evictSinks.delete(token);
|
|
3002
|
+
}
|
|
3003
|
+
},
|
|
2958
3004
|
loadFull: options.engine.loadTranscriptFull,
|
|
2959
3005
|
buildConversationChain: options.engine.buildConversationChain,
|
|
2960
3006
|
resolvePath,
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* 才释放,杜绝 close 竞态下槽位早释的限额绕过)。
|
|
32
32
|
*/
|
|
33
33
|
import type { WebSessionEvent } from './contract.js';
|
|
34
|
-
import type { CursorLedger } from './cursorLedger.js';
|
|
34
|
+
import type { CursorLedger, CursorBinding } from './cursorLedger.js';
|
|
35
35
|
import type { SessionStoreAdapter } from './sessionStoreAdapter.js';
|
|
36
36
|
import { type ProjectionEngineDeps, type ProjectionSourceMessage } from './projection.js';
|
|
37
37
|
/** 投影消息源结构面(engine TranscriptMessage 的结构超集镜像,pack 域零引擎导入)。 */
|
|
@@ -62,6 +62,16 @@ export interface FollowDeps {
|
|
|
62
62
|
limits: FollowLimits;
|
|
63
63
|
signal?: AbortSignal;
|
|
64
64
|
ledger: CursorLedger;
|
|
65
|
+
/**
|
|
66
|
+
* W-FC-1 修形 2(工单 docs/2026-11-28-wfc1-ledger-evict-ticket.md §3 格 2):
|
|
67
|
+
* 活跃 cursor 被账本压力淘汰的 sink 注册/注销面(runtime 持注册表,
|
|
68
|
+
* ledger onActiveEvict 分发后即删)。issue 成功后注册、setTerminal 兜底
|
|
69
|
+
* 注销。inline 类型——零新 export(红线:零新 wire 形/export)。
|
|
70
|
+
*/
|
|
71
|
+
evictRouter: {
|
|
72
|
+
register: (token: string, sink: (token: string, binding: CursorBinding) => void) => void;
|
|
73
|
+
unregister: (token: string) => void;
|
|
74
|
+
};
|
|
65
75
|
/** 引擎 loader 全量基线面(显式 filePath;呈批书 §7.3 钉死形,注入缝)。 */
|
|
66
76
|
loadFull: (filePath: string) => Promise<{
|
|
67
77
|
messages: Map<string, ProjectionSourceMessage>;
|
|
@@ -1160,6 +1160,9 @@ class CursorLedger {
|
|
|
1160
1160
|
this.onActiveEvict = onActiveEvict;
|
|
1161
1161
|
}
|
|
1162
1162
|
issue(binding, payloadBytes = 0) {
|
|
1163
|
+
if (payloadBytes > this.maxPayloadBytes) {
|
|
1164
|
+
throw new WebSessionError("resourceLimit", `ledger payload exceeds cap (${payloadBytes} > ${this.maxPayloadBytes} bytes)`);
|
|
1165
|
+
}
|
|
1163
1166
|
this.evictForInsert(payloadBytes);
|
|
1164
1167
|
const token = randomUUID();
|
|
1165
1168
|
this.entries.set(token, {
|
|
@@ -1495,10 +1498,20 @@ function createFollowSubscription(deps) {
|
|
|
1495
1498
|
terminalRank = rank;
|
|
1496
1499
|
running = false;
|
|
1497
1500
|
disarmLease();
|
|
1498
|
-
for (const t of issuedTokens)
|
|
1501
|
+
for (const t of issuedTokens) {
|
|
1499
1502
|
ledger.unpin(t);
|
|
1503
|
+
deps.evictRouter.unregister(t);
|
|
1504
|
+
}
|
|
1500
1505
|
notify();
|
|
1501
1506
|
}
|
|
1507
|
+
function handleActiveEvict(token, binding) {
|
|
1508
|
+
queueData({
|
|
1509
|
+
...envelope(deps),
|
|
1510
|
+
kind: "resetRequired",
|
|
1511
|
+
generation: binding.generation,
|
|
1512
|
+
reason: "active cursor evicted (ledger pressure)"
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1502
1515
|
function queueData(ev) {
|
|
1503
1516
|
if (terminalEvent || finished)
|
|
1504
1517
|
return;
|
|
@@ -1600,19 +1613,29 @@ function createFollowSubscription(deps) {
|
|
|
1600
1613
|
setTerminal(errorEvent("resourceLimit", `projection exceeds limit (${bytes} bytes)`));
|
|
1601
1614
|
return false;
|
|
1602
1615
|
}
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1616
|
+
let cursor;
|
|
1617
|
+
try {
|
|
1618
|
+
cursor = ledger.issue({
|
|
1619
|
+
v: 1,
|
|
1620
|
+
productId: deps.productId,
|
|
1621
|
+
scopeId: deps.scopeId,
|
|
1622
|
+
sessionId: deps.sessionId,
|
|
1623
|
+
baselineId,
|
|
1624
|
+
generation,
|
|
1625
|
+
revision,
|
|
1626
|
+
byteOffset: offset,
|
|
1627
|
+
ino: anchorIno
|
|
1628
|
+
}, bytes);
|
|
1629
|
+
} catch (e) {
|
|
1630
|
+
if (e instanceof WebSessionError && e.code === "resourceLimit") {
|
|
1631
|
+
setTerminal(errorEvent("resourceLimit", e.message));
|
|
1632
|
+
return false;
|
|
1633
|
+
}
|
|
1634
|
+
throw e;
|
|
1635
|
+
}
|
|
1614
1636
|
ledger.pin(cursor);
|
|
1615
1637
|
issuedTokens.push(cursor);
|
|
1638
|
+
deps.evictRouter.register(cursor, handleActiveEvict);
|
|
1616
1639
|
queueData({
|
|
1617
1640
|
...envelope(deps),
|
|
1618
1641
|
kind: "baseline",
|
|
@@ -1715,19 +1738,29 @@ function createFollowSubscription(deps) {
|
|
|
1715
1738
|
return;
|
|
1716
1739
|
}
|
|
1717
1740
|
revision++;
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1741
|
+
let cursor;
|
|
1742
|
+
try {
|
|
1743
|
+
cursor = ledger.issue({
|
|
1744
|
+
v: 1,
|
|
1745
|
+
productId: deps.productId,
|
|
1746
|
+
scopeId: deps.scopeId,
|
|
1747
|
+
sessionId: deps.sessionId,
|
|
1748
|
+
baselineId,
|
|
1749
|
+
generation,
|
|
1750
|
+
revision,
|
|
1751
|
+
byteOffset: offset,
|
|
1752
|
+
ino: anchorIno
|
|
1753
|
+
}, bytes);
|
|
1754
|
+
} catch (e) {
|
|
1755
|
+
if (e instanceof WebSessionError && e.code === "resourceLimit") {
|
|
1756
|
+
setTerminal(errorEvent("resourceLimit", e.message));
|
|
1757
|
+
return;
|
|
1758
|
+
}
|
|
1759
|
+
throw e;
|
|
1760
|
+
}
|
|
1729
1761
|
ledger.pin(cursor);
|
|
1730
1762
|
issuedTokens.push(cursor);
|
|
1763
|
+
deps.evictRouter.register(cursor, handleActiveEvict);
|
|
1731
1764
|
queueData({
|
|
1732
1765
|
...envelope(deps),
|
|
1733
1766
|
kind: "replacement",
|
|
@@ -2689,7 +2722,12 @@ function createReadonlySessionRuntime(options) {
|
|
|
2689
2722
|
let state = "idle";
|
|
2690
2723
|
const subscriptions = new Set;
|
|
2691
2724
|
let activeReads = 0;
|
|
2692
|
-
const
|
|
2725
|
+
const evictSinks = new Map;
|
|
2726
|
+
const cursorLedger = new CursorLedger(L.ledgerCapacity, L.cursorTtlMs, L.ledgerPayloadBytes, (token, binding) => {
|
|
2727
|
+
const sink = evictSinks.get(token);
|
|
2728
|
+
evictSinks.delete(token);
|
|
2729
|
+
sink?.(token, binding);
|
|
2730
|
+
});
|
|
2693
2731
|
function assertStarted(operation) {
|
|
2694
2732
|
if (state === "idle") {
|
|
2695
2733
|
throw new WebSessionError("closed", "not started");
|
|
@@ -2955,6 +2993,14 @@ function createReadonlySessionRuntime(options) {
|
|
|
2955
2993
|
},
|
|
2956
2994
|
signal,
|
|
2957
2995
|
ledger: cursorLedger,
|
|
2996
|
+
evictRouter: {
|
|
2997
|
+
register: (token, sink) => {
|
|
2998
|
+
evictSinks.set(token, sink);
|
|
2999
|
+
},
|
|
3000
|
+
unregister: (token) => {
|
|
3001
|
+
evictSinks.delete(token);
|
|
3002
|
+
}
|
|
3003
|
+
},
|
|
2958
3004
|
loadFull: options.engine.loadTranscriptFull,
|
|
2959
3005
|
buildConversationChain: options.engine.buildConversationChain,
|
|
2960
3006
|
resolvePath,
|
package/package.json
CHANGED