@xenosystem/agent-interface-core 0.1.3
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/LICENSE +67 -0
- package/dist/agentDiscovery.d.ts +97 -0
- package/dist/agentDiscovery.d.ts.map +1 -0
- package/dist/agentDiscovery.js +93 -0
- package/dist/agentDiscovery.js.map +1 -0
- package/dist/capabilityRouting.d.ts +72 -0
- package/dist/capabilityRouting.d.ts.map +1 -0
- package/dist/capabilityRouting.js +124 -0
- package/dist/capabilityRouting.js.map +1 -0
- package/dist/capabilityTier.d.ts +105 -0
- package/dist/capabilityTier.d.ts.map +1 -0
- package/dist/capabilityTier.js +120 -0
- package/dist/capabilityTier.js.map +1 -0
- package/dist/combinationVerification.d.ts +101 -0
- package/dist/combinationVerification.d.ts.map +1 -0
- package/dist/combinationVerification.js +115 -0
- package/dist/combinationVerification.js.map +1 -0
- package/dist/context/agentAttachedContextPrompt.d.ts +13 -0
- package/dist/context/agentAttachedContextPrompt.d.ts.map +1 -0
- package/dist/context/agentAttachedContextPrompt.js +50 -0
- package/dist/context/agentAttachedContextPrompt.js.map +1 -0
- package/dist/context/agentModelContext.d.ts +77 -0
- package/dist/context/agentModelContext.d.ts.map +1 -0
- package/dist/context/agentModelContext.js +297 -0
- package/dist/context/agentModelContext.js.map +1 -0
- package/dist/fanOutPlanner.d.ts +65 -0
- package/dist/fanOutPlanner.d.ts.map +1 -0
- package/dist/fanOutPlanner.js +78 -0
- package/dist/fanOutPlanner.js.map +1 -0
- package/dist/fleetBoardProjection.d.ts +143 -0
- package/dist/fleetBoardProjection.d.ts.map +1 -0
- package/dist/fleetBoardProjection.js +156 -0
- package/dist/fleetBoardProjection.js.map +1 -0
- package/dist/fleetProjection.d.ts +63 -0
- package/dist/fleetProjection.d.ts.map +1 -0
- package/dist/fleetProjection.js +86 -0
- package/dist/fleetProjection.js.map +1 -0
- package/dist/hostBackedCapabilities.d.ts +50 -0
- package/dist/hostBackedCapabilities.d.ts.map +1 -0
- package/dist/hostBackedCapabilities.js +66 -0
- package/dist/hostBackedCapabilities.js.map +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +134 -0
- package/dist/index.js.map +1 -0
- package/dist/intakeBoardProjection.d.ts +75 -0
- package/dist/intakeBoardProjection.d.ts.map +1 -0
- package/dist/intakeBoardProjection.js +90 -0
- package/dist/intakeBoardProjection.js.map +1 -0
- package/dist/intakeClaim.d.ts +156 -0
- package/dist/intakeClaim.d.ts.map +1 -0
- package/dist/intakeClaim.js +190 -0
- package/dist/intakeClaim.js.map +1 -0
- package/dist/knowledgeBoardProjection.d.ts +57 -0
- package/dist/knowledgeBoardProjection.d.ts.map +1 -0
- package/dist/knowledgeBoardProjection.js +74 -0
- package/dist/knowledgeBoardProjection.js.map +1 -0
- package/dist/landingOverlap.d.ts +127 -0
- package/dist/landingOverlap.d.ts.map +1 -0
- package/dist/landingOverlap.js +107 -0
- package/dist/landingOverlap.js.map +1 -0
- package/dist/landingQueue.d.ts +152 -0
- package/dist/landingQueue.d.ts.map +1 -0
- package/dist/landingQueue.js +258 -0
- package/dist/landingQueue.js.map +1 -0
- package/dist/markdown/markdownWindowsPaths.d.ts +20 -0
- package/dist/markdown/markdownWindowsPaths.d.ts.map +1 -0
- package/dist/markdown/markdownWindowsPaths.js +208 -0
- package/dist/markdown/markdownWindowsPaths.js.map +1 -0
- package/dist/reviewProjection.d.ts +118 -0
- package/dist/reviewProjection.d.ts.map +1 -0
- package/dist/reviewProjection.js +133 -0
- package/dist/reviewProjection.js.map +1 -0
- package/dist/runDiff.d.ts +86 -0
- package/dist/runDiff.d.ts.map +1 -0
- package/dist/runDiff.js +103 -0
- package/dist/runDiff.js.map +1 -0
- package/dist/runtime/agentReasoningEffort.d.ts +22 -0
- package/dist/runtime/agentReasoningEffort.d.ts.map +1 -0
- package/dist/runtime/agentReasoningEffort.js +76 -0
- package/dist/runtime/agentReasoningEffort.js.map +1 -0
- package/dist/runtime/agentRuntimeProvider.d.ts +12 -0
- package/dist/runtime/agentRuntimeProvider.d.ts.map +1 -0
- package/dist/runtime/agentRuntimeProvider.js +294 -0
- package/dist/runtime/agentRuntimeProvider.js.map +1 -0
- package/dist/runtime/agentRuntimeProviderTypes.d.ts +100 -0
- package/dist/runtime/agentRuntimeProviderTypes.d.ts.map +1 -0
- package/dist/runtime/agentRuntimeProviderTypes.js +2 -0
- package/dist/runtime/agentRuntimeProviderTypes.js.map +1 -0
- package/dist/runtime/conversationRuntime.d.ts +53 -0
- package/dist/runtime/conversationRuntime.d.ts.map +1 -0
- package/dist/runtime/conversationRuntime.js +207 -0
- package/dist/runtime/conversationRuntime.js.map +1 -0
- package/dist/runtime/legacyAgentRuntimeEvents.d.ts +65 -0
- package/dist/runtime/legacyAgentRuntimeEvents.d.ts.map +1 -0
- package/dist/runtime/legacyAgentRuntimeEvents.js +104 -0
- package/dist/runtime/legacyAgentRuntimeEvents.js.map +1 -0
- package/dist/runtimeProjection.d.ts +19 -0
- package/dist/runtimeProjection.d.ts.map +1 -0
- package/dist/runtimeProjection.js +133 -0
- package/dist/runtimeProjection.js.map +1 -0
- package/dist/sessionBoardProjection.d.ts +84 -0
- package/dist/sessionBoardProjection.d.ts.map +1 -0
- package/dist/sessionBoardProjection.js +103 -0
- package/dist/sessionBoardProjection.js.map +1 -0
- package/dist/sessionMode.d.ts +115 -0
- package/dist/sessionMode.d.ts.map +1 -0
- package/dist/sessionMode.js +98 -0
- package/dist/sessionMode.js.map +1 -0
- package/dist/workspace/workspaceSelectionContinuation.d.ts +8 -0
- package/dist/workspace/workspaceSelectionContinuation.d.ts.map +1 -0
- package/dist/workspace/workspaceSelectionContinuation.js +18 -0
- package/dist/workspace/workspaceSelectionContinuation.js.map +1 -0
- package/dist/workspaceKnowledge.d.ts +90 -0
- package/dist/workspaceKnowledge.d.ts.map +1 -0
- package/dist/workspaceKnowledge.js +103 -0
- package/dist/workspaceKnowledge.js.map +1 -0
- package/dist/writeLease.d.ts +92 -0
- package/dist/writeLease.d.ts.map +1 -0
- package/dist/writeLease.js +108 -0
- package/dist/writeLease.js.map +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
export const AGENT_MODEL_CONTEXT_STRATEGY_VERSION = 1;
|
|
2
|
+
const DEFAULT_HOT_MESSAGE_COUNT = 12;
|
|
3
|
+
const DEFAULT_MAX_HOT_MESSAGE_CHARACTERS = 8_000;
|
|
4
|
+
const DEFAULT_MAX_LATEST_MESSAGE_CHARACTERS = 20_000;
|
|
5
|
+
const DEFAULT_MAX_SYSTEM_CONTEXT_CHARACTERS = 9_000;
|
|
6
|
+
const DEFAULT_MAX_LEDGER_ITEMS = 28;
|
|
7
|
+
const DEFAULT_MAX_COLD_MEMORY_ITEMS = 32;
|
|
8
|
+
const MEMORY_ANCHOR_PATTERNS = [
|
|
9
|
+
/\bremember\b/i,
|
|
10
|
+
/\bdo not forget\b/i,
|
|
11
|
+
/\bdecision\b/i,
|
|
12
|
+
/\brequirement\b/i,
|
|
13
|
+
/\bconstraint\b/i,
|
|
14
|
+
/\bacceptance criteri(?:a|on)\b/i,
|
|
15
|
+
/\bmust\b/i,
|
|
16
|
+
/\bnever\b/i,
|
|
17
|
+
/\balways\b/i,
|
|
18
|
+
/\bpreference\b/i,
|
|
19
|
+
/\b(?:todo|to-do)\b/i,
|
|
20
|
+
/\b(?:called|named)\b/i,
|
|
21
|
+
/\bnonce\b/i,
|
|
22
|
+
];
|
|
23
|
+
const QUERY_STOP_WORDS = new Set([
|
|
24
|
+
'about', 'after', 'again', 'also', 'been', 'before', 'being', 'could', 'does',
|
|
25
|
+
'from', 'have', 'into', 'just', 'more', 'only', 'other', 'please', 'should',
|
|
26
|
+
'that', 'their', 'then', 'there', 'these', 'they', 'this', 'those', 'what',
|
|
27
|
+
'when', 'where', 'which', 'with', 'would', 'your',
|
|
28
|
+
]);
|
|
29
|
+
function estimateTokens(text) {
|
|
30
|
+
return Math.ceil(text.length / 4);
|
|
31
|
+
}
|
|
32
|
+
function contextDigest(value) {
|
|
33
|
+
let hash = 0x811c9dc5;
|
|
34
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
35
|
+
hash = Math.imul(hash ^ value.charCodeAt(index), 0x01000193);
|
|
36
|
+
}
|
|
37
|
+
return `fnv1a32:${(hash >>> 0).toString(16).padStart(8, '0')}`;
|
|
38
|
+
}
|
|
39
|
+
function clampText(text, maxCharacters) {
|
|
40
|
+
if (text.length <= maxCharacters)
|
|
41
|
+
return text;
|
|
42
|
+
const headLength = Math.max(0, Math.floor(maxCharacters * 0.72));
|
|
43
|
+
const tailLength = Math.max(0, maxCharacters - headLength - 96);
|
|
44
|
+
const head = text.slice(0, headLength).trimEnd();
|
|
45
|
+
const tail = text.slice(text.length - tailLength).trimStart();
|
|
46
|
+
return `${head}\n\n[...compacted ${text.length - head.length - tail.length} chars; raw history remains saved...]\n\n${tail}`.trim();
|
|
47
|
+
}
|
|
48
|
+
function preview(value, maxCharacters = 180) {
|
|
49
|
+
if (value === null || value === undefined)
|
|
50
|
+
return '';
|
|
51
|
+
const text = typeof value === 'string'
|
|
52
|
+
? value
|
|
53
|
+
: JSON.stringify(value);
|
|
54
|
+
return clampText(text.replace(/\s+/g, ' ').trim(), maxCharacters);
|
|
55
|
+
}
|
|
56
|
+
function formatDate(timestamp) {
|
|
57
|
+
if (!timestamp || !Number.isFinite(timestamp))
|
|
58
|
+
return '';
|
|
59
|
+
try {
|
|
60
|
+
return new Date(timestamp).toISOString();
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return '';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function summarizeMessageForColdHistory(message) {
|
|
67
|
+
const when = formatDate(message.timestamp);
|
|
68
|
+
const label = message.role.toUpperCase();
|
|
69
|
+
const text = preview(message.content, 220);
|
|
70
|
+
const suffix = message.toolCalls?.length
|
|
71
|
+
? ` tools=${message.toolCalls.map((tool) => tool.toolName).join(',')}`
|
|
72
|
+
: '';
|
|
73
|
+
return `- ${label}${when ? ` @ ${when}` : ''}: ${text || '(no text)'}${suffix}`;
|
|
74
|
+
}
|
|
75
|
+
function evenlySpacedIndices(length, count) {
|
|
76
|
+
if (length <= 0 || count <= 0)
|
|
77
|
+
return [];
|
|
78
|
+
if (length <= count)
|
|
79
|
+
return Array.from({ length }, (_, index) => index);
|
|
80
|
+
if (count === 1)
|
|
81
|
+
return [0];
|
|
82
|
+
return Array.from({ length: count }, (_, index) => (Math.round((index * (length - 1)) / (count - 1))));
|
|
83
|
+
}
|
|
84
|
+
function anchorScore(message) {
|
|
85
|
+
const text = message.content || '';
|
|
86
|
+
let score = message.role === 'user' ? 1 : 0;
|
|
87
|
+
for (const pattern of MEMORY_ANCHOR_PATTERNS) {
|
|
88
|
+
if (pattern.test(text))
|
|
89
|
+
score += 3;
|
|
90
|
+
}
|
|
91
|
+
if (/\b[A-Z][A-Z0-9_-]{4,}\b/.test(text))
|
|
92
|
+
score += 2;
|
|
93
|
+
if (message.attachments?.length)
|
|
94
|
+
score += 1;
|
|
95
|
+
return score;
|
|
96
|
+
}
|
|
97
|
+
function latestQueryTerms(messages) {
|
|
98
|
+
const latestUser = [...messages].reverse().find((message) => message.role === 'user');
|
|
99
|
+
const terms = (latestUser?.content.toLowerCase().match(/[a-z0-9][a-z0-9._-]{3,}/g) || [])
|
|
100
|
+
.filter((term) => !QUERY_STOP_WORDS.has(term));
|
|
101
|
+
return new Set(terms.slice(0, 48));
|
|
102
|
+
}
|
|
103
|
+
function relevanceScore(message, queryTerms) {
|
|
104
|
+
if (queryTerms.size === 0)
|
|
105
|
+
return 0;
|
|
106
|
+
const words = new Set(message.content.toLowerCase().match(/[a-z0-9][a-z0-9._-]{3,}/g) || []);
|
|
107
|
+
let score = 0;
|
|
108
|
+
for (const term of queryTerms) {
|
|
109
|
+
if (words.has(term))
|
|
110
|
+
score += 1;
|
|
111
|
+
}
|
|
112
|
+
return score;
|
|
113
|
+
}
|
|
114
|
+
function selectColdMemories(coldMessages, allMessages, maxItems) {
|
|
115
|
+
if (coldMessages.length === 0 || maxItems <= 0)
|
|
116
|
+
return [];
|
|
117
|
+
const selected = [];
|
|
118
|
+
const seen = new Set();
|
|
119
|
+
const add = (indexes, kind, limit) => {
|
|
120
|
+
let added = 0;
|
|
121
|
+
for (const index of indexes) {
|
|
122
|
+
if (selected.length >= maxItems || added >= limit || seen.has(index))
|
|
123
|
+
continue;
|
|
124
|
+
const message = coldMessages[index];
|
|
125
|
+
if (!message)
|
|
126
|
+
continue;
|
|
127
|
+
selected.push({ index, kind, message });
|
|
128
|
+
seen.add(index);
|
|
129
|
+
added += 1;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const anchorLimit = Math.min(8, maxItems);
|
|
133
|
+
const relevantLimit = Math.min(6, Math.max(0, maxItems - anchorLimit));
|
|
134
|
+
const milestoneLimit = Math.min(8, Math.max(0, maxItems - anchorLimit - relevantLimit));
|
|
135
|
+
const anchorIndexes = coldMessages
|
|
136
|
+
.map((message, index) => ({ index, score: anchorScore(message) }))
|
|
137
|
+
.filter((candidate) => candidate.score >= 3)
|
|
138
|
+
.sort((left, right) => right.score - left.score || left.index - right.index)
|
|
139
|
+
.map((candidate) => candidate.index);
|
|
140
|
+
add(anchorIndexes, 'anchor', anchorLimit);
|
|
141
|
+
const queryTerms = latestQueryTerms(allMessages);
|
|
142
|
+
const relevantIndexes = coldMessages
|
|
143
|
+
.map((message, index) => ({ index, score: relevanceScore(message, queryTerms) }))
|
|
144
|
+
.filter((candidate) => candidate.score > 0)
|
|
145
|
+
.sort((left, right) => right.score - left.score || right.index - left.index)
|
|
146
|
+
.map((candidate) => candidate.index);
|
|
147
|
+
add(relevantIndexes, 'relevant', relevantLimit);
|
|
148
|
+
add(evenlySpacedIndices(coldMessages.length, milestoneLimit), 'milestone', milestoneLimit);
|
|
149
|
+
const recentCandidateCount = Math.min(coldMessages.length, maxItems);
|
|
150
|
+
add(Array.from({ length: recentCandidateCount }, (_, index) => (coldMessages.length - recentCandidateCount + index)), 'recent', maxItems);
|
|
151
|
+
return selected;
|
|
152
|
+
}
|
|
153
|
+
function toolParamPath(params) {
|
|
154
|
+
if (!params)
|
|
155
|
+
return '';
|
|
156
|
+
const candidates = ['file_path', 'path', 'directory', 'cwd', 'command', 'query', 'appId'];
|
|
157
|
+
for (const key of candidates) {
|
|
158
|
+
const value = params[key];
|
|
159
|
+
if (typeof value === 'string' && value.trim())
|
|
160
|
+
return value.trim();
|
|
161
|
+
}
|
|
162
|
+
return '';
|
|
163
|
+
}
|
|
164
|
+
function summarizeToolCall(tool) {
|
|
165
|
+
const target = toolParamPath(tool.params);
|
|
166
|
+
const artifacts = (tool.artifacts || [])
|
|
167
|
+
.map((artifact) => `${artifact.type}:${artifact.label || artifact.value}=${artifact.value}`)
|
|
168
|
+
.filter(Boolean)
|
|
169
|
+
.slice(0, 3)
|
|
170
|
+
.join('; ');
|
|
171
|
+
const result = tool.result || tool.summary || '';
|
|
172
|
+
const parts = [
|
|
173
|
+
`${tool.toolName}${tool.success === false ? ' failed' : tool.status === 'done' ? ' ok' : ' running'}`,
|
|
174
|
+
target ? `target=${preview(target, 180)}` : '',
|
|
175
|
+
tool.cwd ? `cwd=${preview(tool.cwd, 180)}` : '',
|
|
176
|
+
artifacts ? `artifacts=${preview(artifacts, 320)}` : '',
|
|
177
|
+
result ? `result=${preview(result, 360)}` : '',
|
|
178
|
+
].filter(Boolean);
|
|
179
|
+
return `- ${parts.join(' | ')}`;
|
|
180
|
+
}
|
|
181
|
+
function collectToolLedger(messages, maxLedgerItems) {
|
|
182
|
+
const ledger = [];
|
|
183
|
+
for (const message of messages) {
|
|
184
|
+
for (const tool of message.toolCalls || []) {
|
|
185
|
+
if (tool.status !== 'done' && tool.status !== 'running')
|
|
186
|
+
continue;
|
|
187
|
+
ledger.push(summarizeToolCall(tool));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (ledger.length <= maxLedgerItems)
|
|
191
|
+
return ledger;
|
|
192
|
+
const selected = new Set();
|
|
193
|
+
for (const index of evenlySpacedIndices(ledger.length, Math.min(8, maxLedgerItems))) {
|
|
194
|
+
selected.add(index);
|
|
195
|
+
}
|
|
196
|
+
for (let index = ledger.length - 1; index >= 0 && selected.size < maxLedgerItems; index -= 1) {
|
|
197
|
+
selected.add(index);
|
|
198
|
+
}
|
|
199
|
+
return [...selected].sort((left, right) => left - right).slice(-maxLedgerItems).map((index) => ledger[index]);
|
|
200
|
+
}
|
|
201
|
+
function buildWorkspaceContext(input) {
|
|
202
|
+
if (!input)
|
|
203
|
+
return [];
|
|
204
|
+
const lines = [
|
|
205
|
+
input.workspaceName ? `- workspace: ${input.workspaceName}` : '',
|
|
206
|
+
input.teamName ? `- team: ${input.teamName}` : '',
|
|
207
|
+
input.agentName ? `- agent: ${input.agentName}` : '',
|
|
208
|
+
input.rootDirectory ? `- rootDirectory: ${input.rootDirectory}` : '',
|
|
209
|
+
...(input.grantedDirectories || []).map((directory) => `- grantedDirectory: ${directory}`),
|
|
210
|
+
...(input.activeTasks || []).slice(-8).map((task) => `- task: ${task.status || 'pending'} - ${task.text}`),
|
|
211
|
+
...(input.checkpoints || []).slice(-5).map((checkpoint) => `- checkpoint: ${checkpoint.name}`),
|
|
212
|
+
].filter(Boolean);
|
|
213
|
+
return lines;
|
|
214
|
+
}
|
|
215
|
+
export function appendAgentModelContextToSystemPrompt(systemPrompt, systemPromptContext) {
|
|
216
|
+
const base = (systemPrompt || '').trim();
|
|
217
|
+
const context = systemPromptContext.trim();
|
|
218
|
+
if (!context)
|
|
219
|
+
return base || undefined;
|
|
220
|
+
return base ? `${base}\n\n${context}` : context;
|
|
221
|
+
}
|
|
222
|
+
export function buildAgentModelContext(options) {
|
|
223
|
+
const hotMessageCount = options.hotMessageCount ?? DEFAULT_HOT_MESSAGE_COUNT;
|
|
224
|
+
const maxHotMessageCharacters = options.maxHotMessageCharacters ?? DEFAULT_MAX_HOT_MESSAGE_CHARACTERS;
|
|
225
|
+
const maxLatestMessageCharacters = options.maxLatestMessageCharacters ?? DEFAULT_MAX_LATEST_MESSAGE_CHARACTERS;
|
|
226
|
+
const maxSystemContextCharacters = options.maxSystemContextCharacters ?? DEFAULT_MAX_SYSTEM_CONTEXT_CHARACTERS;
|
|
227
|
+
const maxLedgerItems = options.maxLedgerItems ?? DEFAULT_MAX_LEDGER_ITEMS;
|
|
228
|
+
const maxColdMemoryItems = options.maxColdMemoryItems ?? DEFAULT_MAX_COLD_MEMORY_ITEMS;
|
|
229
|
+
const messages = options.messages.filter((message) => message.role === 'user' || message.role === 'assistant');
|
|
230
|
+
const hotStart = Math.max(0, messages.length - hotMessageCount);
|
|
231
|
+
const coldMessages = messages.slice(0, hotStart);
|
|
232
|
+
const hotMessages = messages.slice(hotStart);
|
|
233
|
+
const latestIndex = hotMessages.length - 1;
|
|
234
|
+
const sentMessages = hotMessages.map((message, index) => {
|
|
235
|
+
const limit = index === latestIndex ? maxLatestMessageCharacters : maxHotMessageCharacters;
|
|
236
|
+
const base = message.content || '';
|
|
237
|
+
const attachmentNotes = (message.attachments || []).map((attachment) => `[Attachment: ${attachment.name}]`).join('\n');
|
|
238
|
+
const content = attachmentNotes ? `${base}\n\n${attachmentNotes}`.trim() : base;
|
|
239
|
+
return {
|
|
240
|
+
role: message.role,
|
|
241
|
+
content: clampText(content, limit),
|
|
242
|
+
};
|
|
243
|
+
});
|
|
244
|
+
const workspaceLines = buildWorkspaceContext(options.workspaceState);
|
|
245
|
+
const coldMemories = selectColdMemories(coldMessages, messages, maxColdMemoryItems);
|
|
246
|
+
const anchorLines = coldMemories
|
|
247
|
+
.filter((memory) => memory.kind === 'anchor' || memory.kind === 'relevant')
|
|
248
|
+
.sort((left, right) => left.index - right.index)
|
|
249
|
+
.map((memory) => summarizeMessageForColdHistory(memory.message));
|
|
250
|
+
const milestoneLines = coldMemories
|
|
251
|
+
.filter((memory) => memory.kind === 'milestone')
|
|
252
|
+
.sort((left, right) => left.index - right.index)
|
|
253
|
+
.map((memory) => summarizeMessageForColdHistory(memory.message));
|
|
254
|
+
const recentColdLines = coldMemories
|
|
255
|
+
.filter((memory) => memory.kind === 'recent')
|
|
256
|
+
.sort((left, right) => left.index - right.index)
|
|
257
|
+
.map((memory) => summarizeMessageForColdHistory(memory.message));
|
|
258
|
+
const ledgerLines = collectToolLedger(messages, maxLedgerItems);
|
|
259
|
+
const rawCharacterCount = messages.reduce((total, message) => (total + (message.content || '').length + (message.toolCalls || []).reduce((toolTotal, tool) => (toolTotal + (tool.result || '').length + JSON.stringify(tool.params || {}).length), 0)), 0);
|
|
260
|
+
const sentCharacterCount = sentMessages.reduce((total, message) => total + message.content.length, 0);
|
|
261
|
+
const contextBlocks = [
|
|
262
|
+
'XENO conversation memory for this turn:',
|
|
263
|
+
'Raw chat, debug events, checkpoints, and full tool payloads remain persisted outside this compact model context.',
|
|
264
|
+
'Use this memory as factual context only; the latest user message remains authoritative.',
|
|
265
|
+
workspaceLines.length ? '\nWorkspace state:\n' + workspaceLines.join('\n') : '',
|
|
266
|
+
anchorLines.length ? '\nDurable conversation anchors and query-relevant history:\n' + anchorLines.join('\n') : '',
|
|
267
|
+
milestoneLines.length ? '\nHistorical timeline milestones:\n' + milestoneLines.join('\n') : '',
|
|
268
|
+
ledgerLines.length ? '\nRecent artifact/tool ledger:\n' + ledgerLines.join('\n') : '',
|
|
269
|
+
recentColdLines.length ? '\nRecent compacted turns:\n' + recentColdLines.join('\n') : '',
|
|
270
|
+
].filter(Boolean).join('\n');
|
|
271
|
+
const systemPromptContext = clampText(contextBlocks, maxSystemContextCharacters);
|
|
272
|
+
const dispatchedContext = JSON.stringify({
|
|
273
|
+
strategyVersion: AGENT_MODEL_CONTEXT_STRATEGY_VERSION,
|
|
274
|
+
messages: sentMessages,
|
|
275
|
+
systemPromptContext,
|
|
276
|
+
});
|
|
277
|
+
return {
|
|
278
|
+
messages: sentMessages,
|
|
279
|
+
systemPromptContext,
|
|
280
|
+
stats: {
|
|
281
|
+
strategyVersion: AGENT_MODEL_CONTEXT_STRATEGY_VERSION,
|
|
282
|
+
contextDigest: contextDigest(dispatchedContext),
|
|
283
|
+
rawMessageCount: messages.length,
|
|
284
|
+
sentMessageCount: sentMessages.length,
|
|
285
|
+
compactedMessageCount: coldMessages.length,
|
|
286
|
+
rawCharacterCount,
|
|
287
|
+
sentCharacterCount: sentCharacterCount + systemPromptContext.length,
|
|
288
|
+
estimatedRawTokens: estimateTokens(messages.map((message) => message.content).join('\n')),
|
|
289
|
+
estimatedSentTokens: estimateTokens(sentMessages.map((message) => message.content).join('\n') + '\n' + systemPromptContext),
|
|
290
|
+
retainedCompactedMessageCount: coldMemories.length,
|
|
291
|
+
retainedAnchorCount: anchorLines.length,
|
|
292
|
+
retainedArtifactCount: ledgerLines.length,
|
|
293
|
+
retainedGrantedDirectoryCount: options.workspaceState?.grantedDirectories?.length || 0,
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=agentModelContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentModelContext.js","sourceRoot":"","sources":["../../src/context/agentModelContext.ts"],"names":[],"mappings":"AAkDA,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAC,CAAA;AAmBrD,MAAM,yBAAyB,GAAG,EAAE,CAAA;AACpC,MAAM,kCAAkC,GAAG,KAAK,CAAA;AAChD,MAAM,qCAAqC,GAAG,MAAM,CAAA;AACpD,MAAM,qCAAqC,GAAG,KAAK,CAAA;AACnD,MAAM,wBAAwB,GAAG,EAAE,CAAA;AACnC,MAAM,6BAA6B,GAAG,EAAE,CAAA;AACxC,MAAM,sBAAsB,GAAG;IAC7B,eAAe;IACf,oBAAoB;IACpB,eAAe;IACf,kBAAkB;IAClB,iBAAiB;IACjB,iCAAiC;IACjC,WAAW;IACX,YAAY;IACZ,aAAa;IACb,iBAAiB;IACjB,qBAAqB;IACrB,uBAAuB;IACvB,YAAY;CACb,CAAA;AACD,MAAM,gB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AAY,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,mBAAmB,CAAC;YAC3H,6BAA6B,EAAE,YAAY,CAAC,MAAM;YAClD,mBAAmB,EAAE,WAAW,CAAC,MAAM;YACvC,qBAAqB,EAAE,WAAW,CAAC,MAAM;YACzC,6BAA6B,EAAE,OAAO,CAAC,cAAc,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAC;SACvF;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who runs what, when several tasks are dispatched at once — ADE §5.2's scheduler.
|
|
3
|
+
*
|
|
4
|
+
* §5.2 asks for "scheduler, router and capability matcher behind host methods".
|
|
5
|
+
* `routeByCapability` answers *who could*; this answers *who gets it*. Kept
|
|
6
|
+
* separate and PURE for the same reason the matcher is: a plan you can inspect
|
|
7
|
+
* before anything starts is reviewable, and a plan is exactly the thing a person
|
|
8
|
+
* wants to see before N agents begin editing their repository.
|
|
9
|
+
*
|
|
10
|
+
* It starts nothing and mutates nothing. Handing the result to something that
|
|
11
|
+
* executes is a separate, deliberate act.
|
|
12
|
+
*
|
|
13
|
+
* ## The three rules
|
|
14
|
+
*
|
|
15
|
+
* 1. **A task that cannot be routed is refused ON ITS OWN.** The batch still
|
|
16
|
+
* plans. Failing all five tasks because the third needs a capability nobody
|
|
17
|
+
* has is the shape that makes fan-out untrustworthy — a user cannot tell
|
|
18
|
+
* which task was the problem, and re-running the batch re-runs the four that
|
|
19
|
+
* were fine.
|
|
20
|
+
* 2. **Load is SPREAD, not stacked.** Every task is eligible for the same
|
|
21
|
+
* providers most of the time, so the obvious implementation — "first
|
|
22
|
+
* eligible" — sends the whole batch to one agent and leaves the fleet idle.
|
|
23
|
+
* That is not a performance nit: fan-out that does not fan out is the
|
|
24
|
+
* feature failing silently.
|
|
25
|
+
* 3. **The plan is DETERMINISTIC.** Same tasks, same catalog, same assignment.
|
|
26
|
+
* A scheduler that shuffles cannot be reviewed before it runs, cannot be
|
|
27
|
+
* tested without tolerating any answer, and cannot be explained afterwards.
|
|
28
|
+
*/
|
|
29
|
+
import type { AgentHarnessCapability, AgentRuntimeProviderDescriptor } from '@xenosystem/agent-interface-contract';
|
|
30
|
+
export interface FanOutTask {
|
|
31
|
+
taskId: string;
|
|
32
|
+
requiredCapabilities?: AgentHarnessCapability[];
|
|
33
|
+
}
|
|
34
|
+
export interface FanOutAssignment {
|
|
35
|
+
taskId: string;
|
|
36
|
+
providerId: string;
|
|
37
|
+
/** Capabilities this provider serves degraded for THIS task. Carried through
|
|
38
|
+
* so the plan shows a worse-but-possible run as such, rather than hiding it
|
|
39
|
+
* behind a successful-looking assignment. */
|
|
40
|
+
degraded: AgentHarnessCapability[];
|
|
41
|
+
}
|
|
42
|
+
export interface FanOutRefusal {
|
|
43
|
+
taskId: string;
|
|
44
|
+
/** Why nothing can run it — the same named reason the matcher produces. */
|
|
45
|
+
reason: string;
|
|
46
|
+
}
|
|
47
|
+
export interface FanOutPlan {
|
|
48
|
+
assignments: FanOutAssignment[];
|
|
49
|
+
refusals: FanOutRefusal[];
|
|
50
|
+
/**
|
|
51
|
+
* How many tasks each provider was given. Present so a caller can SEE the
|
|
52
|
+
* spread rather than trust it — a plan that stacked everything on one agent
|
|
53
|
+
* looks identical to a balanced one from the assignment list alone.
|
|
54
|
+
*/
|
|
55
|
+
loadByProvider: Record<string, number>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Plans a fan-out without starting anything.
|
|
59
|
+
*
|
|
60
|
+
* Tasks are planned in the order given, and each is assigned to its
|
|
61
|
+
* least-loaded eligible provider. Ties break on the provider order from the
|
|
62
|
+
* catalog, which is what makes the whole plan reproducible.
|
|
63
|
+
*/
|
|
64
|
+
export declare function planFanOut(providers: readonly AgentRuntimeProviderDescriptor[], tasks: readonly FanOutTask[]): FanOutPlan;
|
|
65
|
+
//# sourceMappingURL=fanOutPlanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fanOutPlanner.d.ts","sourceRoot":"","sources":["../src/fanOutPlanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,8BAA8B,EAC/B,MAAM,sCAAsC,CAAA;AAI7C,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,oBAAoB,CAAC,EAAE,sBAAsB,EAAE,CAAA;CAChD;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB;;kDAE8C;IAC9C,QAAQ,EAAE,sBAAsB,EAAE,CAAA;CACnC;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,gBAAgB,EAAE,CAAA;IAC/B,QAAQ,EAAE,aAAa,EAAE,CAAA;IACzB;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACvC;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,SAAS,8BAA8B,EAAE,EACpD,KAAK,EAAE,SAAS,UAAU,EAAE,GAC3B,UAAU,CA8CZ"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who runs what, when several tasks are dispatched at once — ADE §5.2's scheduler.
|
|
3
|
+
*
|
|
4
|
+
* §5.2 asks for "scheduler, router and capability matcher behind host methods".
|
|
5
|
+
* `routeByCapability` answers *who could*; this answers *who gets it*. Kept
|
|
6
|
+
* separate and PURE for the same reason the matcher is: a plan you can inspect
|
|
7
|
+
* before anything starts is reviewable, and a plan is exactly the thing a person
|
|
8
|
+
* wants to see before N agents begin editing their repository.
|
|
9
|
+
*
|
|
10
|
+
* It starts nothing and mutates nothing. Handing the result to something that
|
|
11
|
+
* executes is a separate, deliberate act.
|
|
12
|
+
*
|
|
13
|
+
* ## The three rules
|
|
14
|
+
*
|
|
15
|
+
* 1. **A task that cannot be routed is refused ON ITS OWN.** The batch still
|
|
16
|
+
* plans. Failing all five tasks because the third needs a capability nobody
|
|
17
|
+
* has is the shape that makes fan-out untrustworthy — a user cannot tell
|
|
18
|
+
* which task was the problem, and re-running the batch re-runs the four that
|
|
19
|
+
* were fine.
|
|
20
|
+
* 2. **Load is SPREAD, not stacked.** Every task is eligible for the same
|
|
21
|
+
* providers most of the time, so the obvious implementation — "first
|
|
22
|
+
* eligible" — sends the whole batch to one agent and leaves the fleet idle.
|
|
23
|
+
* That is not a performance nit: fan-out that does not fan out is the
|
|
24
|
+
* feature failing silently.
|
|
25
|
+
* 3. **The plan is DETERMINISTIC.** Same tasks, same catalog, same assignment.
|
|
26
|
+
* A scheduler that shuffles cannot be reviewed before it runs, cannot be
|
|
27
|
+
* tested without tolerating any answer, and cannot be explained afterwards.
|
|
28
|
+
*/
|
|
29
|
+
import { routeByCapability } from './capabilityRouting.js';
|
|
30
|
+
/**
|
|
31
|
+
* Plans a fan-out without starting anything.
|
|
32
|
+
*
|
|
33
|
+
* Tasks are planned in the order given, and each is assigned to its
|
|
34
|
+
* least-loaded eligible provider. Ties break on the provider order from the
|
|
35
|
+
* catalog, which is what makes the whole plan reproducible.
|
|
36
|
+
*/
|
|
37
|
+
export function planFanOut(providers, tasks) {
|
|
38
|
+
const assignments = [];
|
|
39
|
+
const refusals = [];
|
|
40
|
+
const load = new Map();
|
|
41
|
+
// Seeded with every provider at 0 so `loadByProvider` reports idle agents as
|
|
42
|
+
// idle. Omitting them would make an unbalanced plan and a small fleet look
|
|
43
|
+
// the same, which is the thing the field exists to distinguish.
|
|
44
|
+
for (const provider of providers)
|
|
45
|
+
load.set(provider.id, 0);
|
|
46
|
+
// Catalog position, for deterministic tie-breaking.
|
|
47
|
+
const order = new Map(providers.map((provider, index) => [provider.id, index]));
|
|
48
|
+
for (const task of tasks) {
|
|
49
|
+
const decision = routeByCapability(providers, task.requiredCapabilities ?? []);
|
|
50
|
+
if (!decision.routable) {
|
|
51
|
+
// Rule 1: this task alone. The rest of the batch still plans.
|
|
52
|
+
refusals.push({ taskId: task.taskId, reason: decision.reason });
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
// Rule 2 + 3: least-loaded, ties broken by catalog order.
|
|
56
|
+
let chosen = decision.matches[0];
|
|
57
|
+
for (const candidate of decision.matches) {
|
|
58
|
+
const candidateLoad = load.get(candidate.providerId) ?? 0;
|
|
59
|
+
const chosenLoad = load.get(chosen.providerId) ?? 0;
|
|
60
|
+
if (candidateLoad < chosenLoad) {
|
|
61
|
+
chosen = candidate;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (candidateLoad === chosenLoad &&
|
|
65
|
+
(order.get(candidate.providerId) ?? 0) < (order.get(chosen.providerId) ?? 0)) {
|
|
66
|
+
chosen = candidate;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
load.set(chosen.providerId, (load.get(chosen.providerId) ?? 0) + 1);
|
|
70
|
+
assignments.push({
|
|
71
|
+
taskId: task.taskId,
|
|
72
|
+
providerId: chosen.providerId,
|
|
73
|
+
degraded: [...chosen.degraded],
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return { assignments, refusals, loadByProvider: Object.fromEntries(load) };
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=fanOutPlanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fanOutPlanner.js","sourceRoot":"","sources":["../src/fanOutPlanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAOH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,C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nD,IAAI,aAAa,GAAG,UAAU,EAAE,CAAC;gBAC/B,MAAM,GAAG,SAAS,CAAA;gBAClB,SAAQ;YACV,CAAC;YACD,IACE,aAAa,KAAK,UAAU;gBAC5B,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAC5E,CAAC;gBACD,MAAM,GAAG,SAAS,CAAA;YACpB,CAAC;QACH,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QACnE,WAAW,CAAC,IAAI,CAAC;YACf,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,QAAQ,EAAE,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC;SAC/B,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAA;AAC5E,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a fleet surface may SHOW — ADE §9 step 6, the presentation half.
|
|
3
|
+
*
|
|
4
|
+
* `fleet.view` answers what the host knows. This decides what a person is told,
|
|
5
|
+
* and in what order. Pure, in `core`, for the same reason `reviewProjection`
|
|
6
|
+
* is: every rule here is about honesty rather than layout, and an honesty rule
|
|
7
|
+
* written in JSX is enforced by whoever writes the next component.
|
|
8
|
+
*
|
|
9
|
+
* ## 🔴 The board is ordered by what needs a human, not by name
|
|
10
|
+
*
|
|
11
|
+
* A fleet view exists to answer one question — *where do I need to look?* Sorted
|
|
12
|
+
* alphabetically it answers a different, useless one. So rows are ranked by
|
|
13
|
+
* attention: a run blocked on a live collision first, then one whose changes
|
|
14
|
+
* another run also touched, then one whose diff has a hole, then whatever is
|
|
15
|
+
* merely working.
|
|
16
|
+
*
|
|
17
|
+
* Ties break on run id so the order is STABLE. A board that reshuffles between
|
|
18
|
+
* polls is unusable for the thing a board is for — noticing what changed.
|
|
19
|
+
*
|
|
20
|
+
* ## Unobserved is its own status
|
|
21
|
+
*
|
|
22
|
+
* `diffComplete` is absent when nobody watched a run, and that is a third state
|
|
23
|
+
* beside complete and incomplete. Folding it into either lies in a different
|
|
24
|
+
* direction each way: "complete" claims a diff nobody collected, "incomplete"
|
|
25
|
+
* sends someone to fix an observation problem that does not exist.
|
|
26
|
+
*/
|
|
27
|
+
/** Mirrors `AgentFleetRun` on the wire, redeclared so `core` stays contract-free
|
|
28
|
+
* in the direction that matters — this package is imported by surfaces that
|
|
29
|
+
* never speak the host protocol directly. */
|
|
30
|
+
export interface FleetBoardRunInput {
|
|
31
|
+
runId: string;
|
|
32
|
+
conversationId?: string;
|
|
33
|
+
workspaceId?: string;
|
|
34
|
+
agentId?: string;
|
|
35
|
+
working: boolean;
|
|
36
|
+
claims: string[];
|
|
37
|
+
changes?: {
|
|
38
|
+
added: number;
|
|
39
|
+
modified: number;
|
|
40
|
+
deleted: number;
|
|
41
|
+
};
|
|
42
|
+
diffComplete?: boolean;
|
|
43
|
+
contestedPaths: string[];
|
|
44
|
+
intakeItemId?: string;
|
|
45
|
+
/** Stopped on a permission prompt. Absent when there is no roster to ask. */
|
|
46
|
+
awaitingApproval?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Messages withheld from this run, awaiting a human (§6 `hold`).
|
|
49
|
+
*
|
|
50
|
+
* Absent when there is no roster to ask. Separate from `awaitingApproval`:
|
|
51
|
+
* that stops the RUN, this stops a message TO it.
|
|
52
|
+
*/
|
|
53
|
+
heldMessages?: number;
|
|
54
|
+
inboundPolicy?: 'accept' | 'hold' | 'refuse';
|
|
55
|
+
isolation?: 'none' | 'sandboxed' | 'unknown';
|
|
56
|
+
isolationMechanism?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface FleetBoardCollisionInput {
|
|
59
|
+
scope: string;
|
|
60
|
+
wantedByRunId: string;
|
|
61
|
+
heldByRunId: string;
|
|
62
|
+
at: string;
|
|
63
|
+
stillHeld: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface FleetBoardInput {
|
|
66
|
+
runs: FleetBoardRunInput[];
|
|
67
|
+
collisions: FleetBoardCollisionInput[];
|
|
68
|
+
coordinationComplete: boolean;
|
|
69
|
+
observationComplete: boolean;
|
|
70
|
+
problems: string[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Why a run is at the top of the board, or that it is not.
|
|
74
|
+
*
|
|
75
|
+
* Ordered by urgency, and the numbers are deliberate: the projection sorts on
|
|
76
|
+
* them, so adding a status between two others is a one-line change rather than
|
|
77
|
+
* a re-reading of a comparator.
|
|
78
|
+
*/
|
|
79
|
+
export declare const FLEET_ATTENTION: {
|
|
80
|
+
/**
|
|
81
|
+
* 🔴 ABOVE `blocked`, deliberately.
|
|
82
|
+
*
|
|
83
|
+
* Both are stopped, but only one of them the reader can clear. A path
|
|
84
|
+
* collision waits on another RUN finishing; a permission prompt waits on the
|
|
85
|
+
* person looking at this board, and every second it sits below something they
|
|
86
|
+
* cannot act on is a second of nothing happening for no reason.
|
|
87
|
+
*/
|
|
88
|
+
readonly 'awaiting-approval': 0;
|
|
89
|
+
readonly blocked: 1;
|
|
90
|
+
readonly contested: 2;
|
|
91
|
+
readonly incomplete: 3;
|
|
92
|
+
readonly working: 4;
|
|
93
|
+
readonly unobserved: 5;
|
|
94
|
+
readonly idle: 6;
|
|
95
|
+
};
|
|
96
|
+
export type FleetAttention = keyof typeof FLEET_ATTENTION;
|
|
97
|
+
export interface FleetBoardRow {
|
|
98
|
+
runId: string;
|
|
99
|
+
attention: FleetAttention;
|
|
100
|
+
working: boolean;
|
|
101
|
+
claims: string[];
|
|
102
|
+
contestedPaths: string[];
|
|
103
|
+
/** §5.1 provenance: the intake item this run came from, when it did. */
|
|
104
|
+
intakeItemId?: string;
|
|
105
|
+
/** Absent when the run is not observed — never zeroed. */
|
|
106
|
+
changes?: {
|
|
107
|
+
added: number;
|
|
108
|
+
modified: number;
|
|
109
|
+
deleted: number;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* How many messages are withheld from this run pending approval.
|
|
113
|
+
*
|
|
114
|
+
* Absent when unknowable, and rendered only when > 0: a row reading
|
|
115
|
+
* "0 awaiting approval" is noise on every run that has none.
|
|
116
|
+
*/
|
|
117
|
+
heldMessages?: number;
|
|
118
|
+
inboundPolicy?: 'accept' | 'hold' | 'refuse';
|
|
119
|
+
isolation?: 'none' | 'sandboxed' | 'unknown';
|
|
120
|
+
isolationMechanism?: string;
|
|
121
|
+
/** One line saying why this row is where it is. */
|
|
122
|
+
headline: string;
|
|
123
|
+
/** True only when this run's changes may be treated as the whole story. */
|
|
124
|
+
diffTrustworthy: boolean;
|
|
125
|
+
}
|
|
126
|
+
export interface FleetBoard {
|
|
127
|
+
rows: FleetBoardRow[];
|
|
128
|
+
/** Collisions a person can still act on — the holder has not released. */
|
|
129
|
+
liveCollisions: FleetBoardCollisionInput[];
|
|
130
|
+
/** Collisions that resolved. Kept: "nobody collided" and "a collision happened
|
|
131
|
+
* and was handled" are different histories. */
|
|
132
|
+
resolvedCollisions: FleetBoardCollisionInput[];
|
|
133
|
+
/**
|
|
134
|
+
* Present whenever the board is not the whole picture. A fleet view that
|
|
135
|
+
* showed three collisions when five happened would be read as "mostly fine",
|
|
136
|
+
* so the limit is stated rather than implied by a short list.
|
|
137
|
+
*/
|
|
138
|
+
notice?: string;
|
|
139
|
+
/** True only when nothing is known to be missing. */
|
|
140
|
+
trustworthy: boolean;
|
|
141
|
+
}
|
|
142
|
+
export declare function projectFleetBoard(input: FleetBoardInput): FleetBoard;
|
|
143
|
+
//# sourceMappingURL=fleetBoardProjection.d.ts.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