@aionis/sdk 0.1.1 → 0.1.6
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 +121 -2
- package/dist/index.d.ts +292 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +844 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -41,6 +41,351 @@ function rehydrateHintMemoryIds(value) {
|
|
|
41
41
|
.map((entry) => asRecord(entry)?.memory_id)
|
|
42
42
|
.filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
43
43
|
}
|
|
44
|
+
function rehydrateHintArray(value) {
|
|
45
|
+
if (!Array.isArray(value))
|
|
46
|
+
return [];
|
|
47
|
+
return value.flatMap((entry) => {
|
|
48
|
+
const record = asRecord(entry);
|
|
49
|
+
const memoryId = record?.memory_id;
|
|
50
|
+
if (!record || typeof memoryId !== "string" || memoryId.length === 0)
|
|
51
|
+
return [];
|
|
52
|
+
const reason = typeof record.reason === "string" && record.reason.length > 0 ? record.reason : undefined;
|
|
53
|
+
return [{
|
|
54
|
+
memory_id: memoryId,
|
|
55
|
+
...(reason ? { reason } : {}),
|
|
56
|
+
required: record.required === undefined ? true : record.required !== false,
|
|
57
|
+
}];
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function commandPostureArray(value) {
|
|
61
|
+
if (!Array.isArray(value))
|
|
62
|
+
return [];
|
|
63
|
+
return value.flatMap((entry) => {
|
|
64
|
+
const record = asRecord(entry);
|
|
65
|
+
if (!record)
|
|
66
|
+
return [];
|
|
67
|
+
const posture = record.posture;
|
|
68
|
+
const surface = record.surface;
|
|
69
|
+
const memoryId = record.memory_id;
|
|
70
|
+
const instruction = record.instruction;
|
|
71
|
+
const reason = record.reason;
|
|
72
|
+
if (!isCommandPostureKind(posture)
|
|
73
|
+
|| !isCommandPostureSurface(surface)
|
|
74
|
+
|| typeof memoryId !== "string"
|
|
75
|
+
|| memoryId.length === 0
|
|
76
|
+
|| typeof instruction !== "string"
|
|
77
|
+
|| instruction.length === 0
|
|
78
|
+
|| typeof reason !== "string"
|
|
79
|
+
|| reason.length === 0) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
return [{
|
|
83
|
+
posture,
|
|
84
|
+
surface,
|
|
85
|
+
memory_id: memoryId,
|
|
86
|
+
instruction,
|
|
87
|
+
reason,
|
|
88
|
+
target_files: stringArray(record.target_files),
|
|
89
|
+
}];
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function isRouteContractSource(value) {
|
|
93
|
+
return value === "target_files"
|
|
94
|
+
|| value === "should_continue"
|
|
95
|
+
|| value === "inspect_first"
|
|
96
|
+
|| value === "must_not";
|
|
97
|
+
}
|
|
98
|
+
function routeContractTargetArray(value) {
|
|
99
|
+
if (!Array.isArray(value))
|
|
100
|
+
return [];
|
|
101
|
+
return value.flatMap((entry) => {
|
|
102
|
+
const record = asRecord(entry);
|
|
103
|
+
if (!record || typeof record.target !== "string" || record.target.length === 0 || !isRouteContractSource(record.source)) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
const sourceMemoryId = typeof record.source_memory_id === "string" && record.source_memory_id.length > 0
|
|
107
|
+
? record.source_memory_id
|
|
108
|
+
: undefined;
|
|
109
|
+
const reason = typeof record.reason === "string" && record.reason.length > 0 ? record.reason : undefined;
|
|
110
|
+
return [{
|
|
111
|
+
target: record.target,
|
|
112
|
+
...(sourceMemoryId ? { source_memory_id: sourceMemoryId } : {}),
|
|
113
|
+
source: record.source,
|
|
114
|
+
...(reason ? { reason } : {}),
|
|
115
|
+
}];
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function routeContractActiveTargetArray(value) {
|
|
119
|
+
const records = Array.isArray(value) ? value : [];
|
|
120
|
+
return routeContractTargetArray(records).map((entry, index) => {
|
|
121
|
+
const record = asRecord(records[index]);
|
|
122
|
+
return {
|
|
123
|
+
...entry,
|
|
124
|
+
artifact_status: record?.artifact_status === "may_be_absent" ? "may_be_absent" : "unknown",
|
|
125
|
+
missing_policy: "restore_or_create_if_task_consistent_or_rehydrate",
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function routeContractPendingArtifactArray(value) {
|
|
130
|
+
const records = Array.isArray(value) ? value : [];
|
|
131
|
+
return routeContractTargetArray(records).map((entry, index) => {
|
|
132
|
+
const record = asRecord(records[index]);
|
|
133
|
+
const actions = stringArray(record?.allowed_actions).filter((action) => action === "create" || action === "restore" || action === "rehydrate" || action === "report_conflict");
|
|
134
|
+
const preferred = stringArray(record?.preferred_action_order).filter((action) => action === "create" || action === "restore" || action === "rehydrate" || action === "report_conflict");
|
|
135
|
+
return {
|
|
136
|
+
...entry,
|
|
137
|
+
status: "unknown_until_host_observation",
|
|
138
|
+
when: "if_active_target_is_missing",
|
|
139
|
+
allowed_actions: actions.length > 0 ? actions : ["create", "restore", "rehydrate", "report_conflict"],
|
|
140
|
+
preferred_action_order: preferred.length > 0 ? preferred : ["create", "restore", "rehydrate", "report_conflict"],
|
|
141
|
+
terminal_inspect_allowed: false,
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function routeContractEvidenceSourceArray(value) {
|
|
146
|
+
return routeContractTargetArray(value).map((entry) => ({
|
|
147
|
+
...entry,
|
|
148
|
+
evidence_use: "reference_only",
|
|
149
|
+
direction_policy: "must_not_be_primary_route",
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
function routeContractBlockedRouteArray(value) {
|
|
153
|
+
return routeContractTargetArray(value).map((entry) => ({
|
|
154
|
+
...entry,
|
|
155
|
+
direction_policy: "blocked_route",
|
|
156
|
+
evidence_use: "counter_evidence_only",
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
function routeContractActionPolicy(value) {
|
|
160
|
+
const record = asRecord(value);
|
|
161
|
+
const preferred = stringArray(record?.missing_active_target_preferred_order).filter((action) => action === "create" || action === "restore" || action === "rehydrate" || action === "report_conflict");
|
|
162
|
+
return {
|
|
163
|
+
missing_active_target_preferred_order: preferred.length > 0 ? preferred : ["create", "restore", "rehydrate", "report_conflict"],
|
|
164
|
+
terminal_inspect_allowed: false,
|
|
165
|
+
reference_fallback_requires: "explicit_raw_evidence_or_operator_confirmation",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function routeContractMemoryIds(value) {
|
|
169
|
+
const contract = asRecord(value);
|
|
170
|
+
if (!contract)
|
|
171
|
+
return [];
|
|
172
|
+
const rows = [
|
|
173
|
+
...routeContractTargetArray(contract.active_targets),
|
|
174
|
+
...routeContractTargetArray(contract.pending_artifacts),
|
|
175
|
+
...routeContractTargetArray(contract.reference_only_targets),
|
|
176
|
+
...routeContractTargetArray(contract.blocked_direction_targets),
|
|
177
|
+
...routeContractTargetArray(contract.evidence_sources),
|
|
178
|
+
...routeContractTargetArray(contract.blocked_routes),
|
|
179
|
+
];
|
|
180
|
+
return rows
|
|
181
|
+
.map((entry) => entry.source_memory_id)
|
|
182
|
+
.filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
183
|
+
}
|
|
184
|
+
function uniqueStrings(values) {
|
|
185
|
+
return Array.from(new Set(values.filter((entry) => entry.length > 0)));
|
|
186
|
+
}
|
|
187
|
+
function guideTraceId(value) {
|
|
188
|
+
const entry = asRecord(value)?.guide_trace_id;
|
|
189
|
+
return typeof entry === "string" && entry.length > 0 ? entry : null;
|
|
190
|
+
}
|
|
191
|
+
function safeAgentPromptFromGuide(guide) {
|
|
192
|
+
try {
|
|
193
|
+
return agentPromptFromGuide(guide);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return "";
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function receiptFromGuideTrace(guide) {
|
|
200
|
+
const guideRecord = asRecord(guide);
|
|
201
|
+
const candidates = [
|
|
202
|
+
asRecord(asRecord(guideRecord?.memory_decision_trace)?.memory_use_receipt),
|
|
203
|
+
asRecord(guideRecord?.memory_use_receipt),
|
|
204
|
+
asRecord(asRecord(guideRecord?.agent_context)?.memory_use_receipt),
|
|
205
|
+
];
|
|
206
|
+
const receipt = candidates.find((entry) => entry?.contract_version === "aionis_memory_use_receipt_v1");
|
|
207
|
+
return receipt ? receipt : null;
|
|
208
|
+
}
|
|
209
|
+
function decisionSummariesFromSurfaces(input) {
|
|
210
|
+
const rows = [];
|
|
211
|
+
const seen = new Set();
|
|
212
|
+
const push = (entry) => {
|
|
213
|
+
if (seen.has(entry.memory_id))
|
|
214
|
+
return;
|
|
215
|
+
seen.add(entry.memory_id);
|
|
216
|
+
rows.push(entry);
|
|
217
|
+
};
|
|
218
|
+
for (const memoryId of input.useNow) {
|
|
219
|
+
push({
|
|
220
|
+
memory_id: memoryId,
|
|
221
|
+
agent_surface: "use_now",
|
|
222
|
+
decision_kind: "used",
|
|
223
|
+
actionable: true,
|
|
224
|
+
reason_codes: ["agent_context.use_now_memory_ids"],
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
for (const memoryId of input.inspect) {
|
|
228
|
+
push({
|
|
229
|
+
memory_id: memoryId,
|
|
230
|
+
agent_surface: "inspect_before_use",
|
|
231
|
+
decision_kind: "downgraded",
|
|
232
|
+
actionable: false,
|
|
233
|
+
reason_codes: ["agent_context.inspect_before_use_memory_ids"],
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
for (const memoryId of input.doNotUse) {
|
|
237
|
+
push({
|
|
238
|
+
memory_id: memoryId,
|
|
239
|
+
agent_surface: "do_not_use",
|
|
240
|
+
decision_kind: "blocked",
|
|
241
|
+
actionable: false,
|
|
242
|
+
reason_codes: ["agent_context.do_not_use_memory_ids"],
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
for (const memoryId of input.rehydrate) {
|
|
246
|
+
push({
|
|
247
|
+
memory_id: memoryId,
|
|
248
|
+
agent_surface: "rehydrate",
|
|
249
|
+
decision_kind: "rehydrate",
|
|
250
|
+
actionable: false,
|
|
251
|
+
reason_codes: ["agent_context.rehydrate_hints"],
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return rows;
|
|
255
|
+
}
|
|
256
|
+
function generatedMemoryUseReceipt(guide) {
|
|
257
|
+
const context = asRecord(agentContextFromGuide(guide));
|
|
258
|
+
const useNow = uniqueStrings(stringArray(context?.use_now_memory_ids));
|
|
259
|
+
const inspect = uniqueStrings(stringArray(context?.inspect_before_use_memory_ids));
|
|
260
|
+
const doNotUse = uniqueStrings(stringArray(context?.do_not_use_memory_ids));
|
|
261
|
+
const rehydrate = uniqueStrings(rehydrateHintMemoryIds(context?.rehydrate_hints));
|
|
262
|
+
const exposed = uniqueStrings([
|
|
263
|
+
...stringArray(context?.memory_ids),
|
|
264
|
+
...useNow,
|
|
265
|
+
...inspect,
|
|
266
|
+
...doNotUse,
|
|
267
|
+
...rehydrate,
|
|
268
|
+
...commandPostureArray(context?.command_posture).map((entry) => entry.memory_id),
|
|
269
|
+
...routeContractMemoryIds(context?.route_contract),
|
|
270
|
+
]);
|
|
271
|
+
const prompt = safeAgentPromptFromGuide(guide);
|
|
272
|
+
return {
|
|
273
|
+
contract_version: "aionis_memory_use_receipt_v1",
|
|
274
|
+
intended_use: "memory_use_audit",
|
|
275
|
+
agent_prompt_included: false,
|
|
276
|
+
runtime_mutation: false,
|
|
277
|
+
guide_trace_id: guideTraceId(guide),
|
|
278
|
+
history_used: exposed.length > 0,
|
|
279
|
+
actionable_history_used: useNow.length > 0,
|
|
280
|
+
prompt_char_count: prompt.length,
|
|
281
|
+
exposed_memory_ids: exposed,
|
|
282
|
+
use_now_memory_ids: useNow,
|
|
283
|
+
inspect_before_use_memory_ids: inspect,
|
|
284
|
+
do_not_use_memory_ids: doNotUse,
|
|
285
|
+
rehydrate_memory_ids: rehydrate,
|
|
286
|
+
attributed_memory_ids: [],
|
|
287
|
+
unattributed_recalled_memory_ids: [],
|
|
288
|
+
read_only_signal_memory_ids: uniqueStrings([...inspect, ...doNotUse, ...rehydrate]),
|
|
289
|
+
decision_summaries: decisionSummariesFromSurfaces({ useNow, inspect, doNotUse, rehydrate }),
|
|
290
|
+
risk_flags: stringArray(asRecord(context?.risk)?.reasons),
|
|
291
|
+
summary: useNow.length > 0
|
|
292
|
+
? "Aionis exposed adjudicated actionable execution memory."
|
|
293
|
+
: exposed.length > 0
|
|
294
|
+
? "Aionis exposed adjudicated non-actionable memory surfaces."
|
|
295
|
+
: "Aionis did not expose reusable memory for this guide.",
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function targetList(rows) {
|
|
299
|
+
return uniqueStrings(rows.map((entry) => entry.target));
|
|
300
|
+
}
|
|
301
|
+
function repoPresenceMap(state) {
|
|
302
|
+
const out = new Map();
|
|
303
|
+
for (const target of state?.existing_files ?? [])
|
|
304
|
+
out.set(target, true);
|
|
305
|
+
for (const target of state?.missing_files ?? [])
|
|
306
|
+
out.set(target, false);
|
|
307
|
+
for (const entry of state?.files ?? [])
|
|
308
|
+
out.set(entry.target, entry.exists);
|
|
309
|
+
return out;
|
|
310
|
+
}
|
|
311
|
+
function truncateText(text, maxChars) {
|
|
312
|
+
if (maxChars <= 0)
|
|
313
|
+
return "";
|
|
314
|
+
if (text.length <= maxChars)
|
|
315
|
+
return text;
|
|
316
|
+
const marker = "\n...[truncated by Aionis SDK context budget]...";
|
|
317
|
+
if (maxChars <= marker.length)
|
|
318
|
+
return marker.slice(0, maxChars);
|
|
319
|
+
return `${text.slice(0, maxChars - marker.length).trimEnd()}${marker}`;
|
|
320
|
+
}
|
|
321
|
+
function defaultExecutionPromptBudget(profile) {
|
|
322
|
+
switch (profile) {
|
|
323
|
+
case "compact": return 6_000;
|
|
324
|
+
case "high_recall": return 24_000;
|
|
325
|
+
case "balanced": return 12_000;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function taskLines(task) {
|
|
329
|
+
if (!task)
|
|
330
|
+
return [];
|
|
331
|
+
if (typeof task === "string")
|
|
332
|
+
return [`- ${task}`];
|
|
333
|
+
return [
|
|
334
|
+
task.task_signature ? `- task_signature: ${task.task_signature}` : "",
|
|
335
|
+
task.run_id ? `- run_id: ${task.run_id}` : "",
|
|
336
|
+
task.query_text ? `- query: ${task.query_text}` : "",
|
|
337
|
+
task.goal ? `- goal: ${task.goal}` : "",
|
|
338
|
+
].filter((entry) => entry.length > 0);
|
|
339
|
+
}
|
|
340
|
+
function bulletLines(values, empty) {
|
|
341
|
+
return values.length > 0 ? values.map((entry) => `- ${entry}`) : [`- ${empty}`];
|
|
342
|
+
}
|
|
343
|
+
function postureLines(rows, posture, empty) {
|
|
344
|
+
const filtered = rows.filter((entry) => entry.posture === posture);
|
|
345
|
+
if (filtered.length === 0)
|
|
346
|
+
return [`- ${empty}`];
|
|
347
|
+
return filtered.map((entry) => {
|
|
348
|
+
const targets = entry.target_files.length > 0 ? ` targets=${entry.target_files.join(", ")}` : "";
|
|
349
|
+
return `- ${entry.memory_id}: ${entry.instruction} (${entry.reason})${targets}`;
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
function rehydrateRequestsFromGuide(guide) {
|
|
353
|
+
const context = asRecord(agentContextFromGuide(guide));
|
|
354
|
+
const fromHints = rehydrateHintArray(context?.rehydrate_hints);
|
|
355
|
+
const fromPosture = commandPostureArray(context?.command_posture)
|
|
356
|
+
.filter((entry) => entry.posture === "rehydrate_first")
|
|
357
|
+
.map((entry) => ({
|
|
358
|
+
memory_id: entry.memory_id,
|
|
359
|
+
reason: entry.reason || entry.instruction,
|
|
360
|
+
required: true,
|
|
361
|
+
}));
|
|
362
|
+
const byId = new Map();
|
|
363
|
+
for (const entry of [...fromHints, ...fromPosture]) {
|
|
364
|
+
const previous = byId.get(entry.memory_id);
|
|
365
|
+
byId.set(entry.memory_id, {
|
|
366
|
+
memory_id: entry.memory_id,
|
|
367
|
+
reason: previous?.reason ?? entry.reason,
|
|
368
|
+
required: (previous?.required ?? false) || entry.required,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
return Array.from(byId.values());
|
|
372
|
+
}
|
|
373
|
+
function isCommandPostureKind(value) {
|
|
374
|
+
return value === "must_not"
|
|
375
|
+
|| value === "should_continue"
|
|
376
|
+
|| value === "inspect_first"
|
|
377
|
+
|| value === "rehydrate_first"
|
|
378
|
+
|| value === "optional_context";
|
|
379
|
+
}
|
|
380
|
+
function isCommandPostureSurface(value) {
|
|
381
|
+
return value === "current"
|
|
382
|
+
|| value === "procedure"
|
|
383
|
+
|| value === "use_now"
|
|
384
|
+
|| value === "inspect_before_use"
|
|
385
|
+
|| value === "do_not_use"
|
|
386
|
+
|| value === "rehydrate"
|
|
387
|
+
|| value === "context";
|
|
388
|
+
}
|
|
44
389
|
function rememberNodeType(kind) {
|
|
45
390
|
switch (kind) {
|
|
46
391
|
case "preference": return "self_model";
|
|
@@ -92,6 +437,157 @@ function rememberBody(body) {
|
|
|
92
437
|
}),
|
|
93
438
|
});
|
|
94
439
|
}
|
|
440
|
+
function requiredString(value, message) {
|
|
441
|
+
const trimmed = value?.trim();
|
|
442
|
+
if (!trimmed)
|
|
443
|
+
throw new Error(message);
|
|
444
|
+
return trimmed;
|
|
445
|
+
}
|
|
446
|
+
function executionMemoryLane(input) {
|
|
447
|
+
if (input.memory_lane)
|
|
448
|
+
return input.memory_lane;
|
|
449
|
+
return input.team_id?.trim() ? "shared" : "private";
|
|
450
|
+
}
|
|
451
|
+
function executionResultSummary(input) {
|
|
452
|
+
if (!input.outcome || input.outcome === "unknown")
|
|
453
|
+
return undefined;
|
|
454
|
+
return stripUndefined({
|
|
455
|
+
status: input.outcome === "succeeded" ? "passed" : input.outcome,
|
|
456
|
+
summary: input.summary,
|
|
457
|
+
evidence_refs: input.evidence_ref ? [input.evidence_ref] : undefined,
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
function executionFeedbackOutcome(input) {
|
|
461
|
+
if (input.feedback_outcome)
|
|
462
|
+
return input.feedback_outcome;
|
|
463
|
+
if (input.outcome === "succeeded")
|
|
464
|
+
return "positive";
|
|
465
|
+
if (input.outcome === "failed" || input.outcome === "blocked" || input.outcome === "interrupted")
|
|
466
|
+
return "negative";
|
|
467
|
+
return "neutral";
|
|
468
|
+
}
|
|
469
|
+
function executionVerifierStatus(input) {
|
|
470
|
+
if (input.verifier_status)
|
|
471
|
+
return input.verifier_status;
|
|
472
|
+
if (input.outcome === "succeeded")
|
|
473
|
+
return "passed";
|
|
474
|
+
if (input.outcome === "failed" || input.outcome === "blocked" || input.outcome === "interrupted")
|
|
475
|
+
return "failed";
|
|
476
|
+
return "unknown";
|
|
477
|
+
}
|
|
478
|
+
function executionToolStatus(input) {
|
|
479
|
+
if (input.tool_status)
|
|
480
|
+
return input.tool_status;
|
|
481
|
+
if (input.outcome === "succeeded")
|
|
482
|
+
return "succeeded";
|
|
483
|
+
if (input.outcome === "failed" || input.outcome === "blocked" || input.outcome === "interrupted")
|
|
484
|
+
return "failed";
|
|
485
|
+
return "unknown";
|
|
486
|
+
}
|
|
487
|
+
function executionAgentId(input) {
|
|
488
|
+
return requiredString(input.agent_id, "Aionis execution helper requires agent_id.");
|
|
489
|
+
}
|
|
490
|
+
function executionRole(input) {
|
|
491
|
+
return input.role ?? "agent";
|
|
492
|
+
}
|
|
493
|
+
function executionScopeOptions(input) {
|
|
494
|
+
return stripUndefined({
|
|
495
|
+
tenant_id: input.tenant_id,
|
|
496
|
+
scope: input.scope,
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
function executionObserveBase(input) {
|
|
500
|
+
const memoryLane = executionMemoryLane(input);
|
|
501
|
+
if (memoryLane === "shared" && !input.team_id?.trim()) {
|
|
502
|
+
throw new Error("Aionis shared execution memory requires team_id. Use memory_lane: \"private\" for single-agent memory.");
|
|
503
|
+
}
|
|
504
|
+
const agentId = executionAgentId(input);
|
|
505
|
+
return stripUndefined({
|
|
506
|
+
auto_embed: input.auto_embed ?? true,
|
|
507
|
+
memory_lane: memoryLane,
|
|
508
|
+
producer_agent_id: agentId,
|
|
509
|
+
owner_agent_id: memoryLane === "private" ? agentId : undefined,
|
|
510
|
+
owner_team_id: input.team_id,
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
function executionPayload(input) {
|
|
514
|
+
const result = executionResultSummary(input);
|
|
515
|
+
return stripUndefined({
|
|
516
|
+
run_id: input.run_id,
|
|
517
|
+
task_id: input.task_id,
|
|
518
|
+
task_family: input.task_family,
|
|
519
|
+
task_signature: input.task_signature,
|
|
520
|
+
workflow_signature: input.workflow_signature,
|
|
521
|
+
title: input.title,
|
|
522
|
+
summary: input.summary,
|
|
523
|
+
outcome: input.outcome ?? "unknown",
|
|
524
|
+
target_files: input.target_files,
|
|
525
|
+
workflow_steps: input.workflow_steps,
|
|
526
|
+
tool_set: input.tool_set,
|
|
527
|
+
acceptance_checks: input.acceptance_checks,
|
|
528
|
+
continuation_hint: input.continuation_hint,
|
|
529
|
+
resume_hint: input.resume_hint,
|
|
530
|
+
reuse_hint: input.reuse_hint,
|
|
531
|
+
confidence: input.confidence,
|
|
532
|
+
raw_ref: input.raw_ref,
|
|
533
|
+
evidence_ref: input.evidence_ref,
|
|
534
|
+
evidence: input.evidence,
|
|
535
|
+
artifacts: input.artifacts,
|
|
536
|
+
verification: input.verification,
|
|
537
|
+
slots: stripUndefined({
|
|
538
|
+
task_signature: input.task_signature,
|
|
539
|
+
...(result ? { execution_result_summary: result } : {}),
|
|
540
|
+
...(input.slots ?? {}),
|
|
541
|
+
}),
|
|
542
|
+
...(input.execution ?? {}),
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
function executionHandoffPayload(input) {
|
|
546
|
+
const agentId = executionAgentId(input);
|
|
547
|
+
const memoryLane = executionMemoryLane(input);
|
|
548
|
+
const anchor = input.anchor ?? `${input.task_signature}:${input.run_id}:${agentId}`;
|
|
549
|
+
const handoffKind = input.handoff_kind ?? "task_handoff";
|
|
550
|
+
return stripUndefined({
|
|
551
|
+
memory_lane: memoryLane,
|
|
552
|
+
actor: agentId,
|
|
553
|
+
producer_agent_id: agentId,
|
|
554
|
+
owner_agent_id: memoryLane === "private" ? agentId : undefined,
|
|
555
|
+
owner_team_id: input.team_id,
|
|
556
|
+
anchor,
|
|
557
|
+
handoff_kind: handoffKind,
|
|
558
|
+
file_path: input.file_path,
|
|
559
|
+
repo_root: input.repo_root,
|
|
560
|
+
symbol: input.symbol,
|
|
561
|
+
task_family: input.task_family,
|
|
562
|
+
task_signature: input.task_signature,
|
|
563
|
+
workflow_signature: input.workflow_signature,
|
|
564
|
+
title: input.title,
|
|
565
|
+
summary: input.summary,
|
|
566
|
+
handoff_text: input.handoff_text ?? input.continuation_hint ?? input.summary,
|
|
567
|
+
risk: input.risk,
|
|
568
|
+
acceptance_checks: input.acceptance_checks,
|
|
569
|
+
tags: input.tags,
|
|
570
|
+
target_files: input.target_files,
|
|
571
|
+
next_action: input.next_action ?? input.continuation_hint,
|
|
572
|
+
must_change: input.must_change,
|
|
573
|
+
must_remove: input.must_remove,
|
|
574
|
+
must_keep: input.must_keep,
|
|
575
|
+
execution_result_summary: executionResultSummary(input),
|
|
576
|
+
execution_artifacts: input.artifacts,
|
|
577
|
+
execution_evidence: input.evidence,
|
|
578
|
+
execution_state_v1: input.execution_state_v1,
|
|
579
|
+
execution_packet_v1: input.execution_packet_v1,
|
|
580
|
+
control_profile_v1: input.control_profile_v1,
|
|
581
|
+
execution_transitions_v1: input.execution_transitions_v1,
|
|
582
|
+
execution_tree_disabled: input.execution_tree_disabled,
|
|
583
|
+
execution_tree_default_disabled: input.execution_tree_default_disabled,
|
|
584
|
+
execution_tree_v1: input.execution_tree_v1,
|
|
585
|
+
execution_tree_operations_v1: input.execution_tree_operations_v1,
|
|
586
|
+
trajectory: input.trajectory,
|
|
587
|
+
trajectory_hints: input.trajectory_hints,
|
|
588
|
+
...(input.handoff ?? {}),
|
|
589
|
+
});
|
|
590
|
+
}
|
|
95
591
|
async function readResponseBody(response) {
|
|
96
592
|
const text = await response.text();
|
|
97
593
|
if (!text)
|
|
@@ -104,6 +600,7 @@ async function readResponseBody(response) {
|
|
|
104
600
|
}
|
|
105
601
|
}
|
|
106
602
|
export class AionisClient {
|
|
603
|
+
execution;
|
|
107
604
|
baseUrl;
|
|
108
605
|
apiKey;
|
|
109
606
|
tenantId;
|
|
@@ -119,6 +616,7 @@ export class AionisClient {
|
|
|
119
616
|
this.headers = { ...(options.headers ?? {}) };
|
|
120
617
|
this.defaultGuideMode = options.default_guide_mode === undefined ? "full_power" : options.default_guide_mode;
|
|
121
618
|
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
619
|
+
this.execution = new AionisExecutionClient(this);
|
|
122
620
|
}
|
|
123
621
|
async observe(body, options) {
|
|
124
622
|
return this.post("/v1/observe", body, options);
|
|
@@ -172,14 +670,24 @@ export class AionisClient {
|
|
|
172
670
|
return payload;
|
|
173
671
|
}
|
|
174
672
|
guideBody(body, options) {
|
|
175
|
-
|
|
176
|
-
return body;
|
|
673
|
+
const compactBody = stripUndefined(body);
|
|
177
674
|
const guideMode = options?.guide_mode === undefined ? this.defaultGuideMode : options.guide_mode;
|
|
675
|
+
if (compactBody.mode !== undefined)
|
|
676
|
+
return compactBody;
|
|
677
|
+
if (compactBody.context_mode !== undefined) {
|
|
678
|
+
if (compactBody.context_mode === "compact_agent" && guideMode) {
|
|
679
|
+
return {
|
|
680
|
+
mode: guideMode,
|
|
681
|
+
...compactBody,
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
return compactBody;
|
|
685
|
+
}
|
|
178
686
|
if (!guideMode)
|
|
179
|
-
return
|
|
687
|
+
return compactBody;
|
|
180
688
|
return {
|
|
181
689
|
mode: guideMode,
|
|
182
|
-
...
|
|
690
|
+
...compactBody,
|
|
183
691
|
};
|
|
184
692
|
}
|
|
185
693
|
requestHeaders(options) {
|
|
@@ -191,6 +699,147 @@ export class AionisClient {
|
|
|
191
699
|
};
|
|
192
700
|
}
|
|
193
701
|
}
|
|
702
|
+
export class AionisExecutionClient {
|
|
703
|
+
client;
|
|
704
|
+
constructor(client) {
|
|
705
|
+
this.client = client;
|
|
706
|
+
}
|
|
707
|
+
compileAgentContext(input) {
|
|
708
|
+
return compileExecutionAgentContext(input);
|
|
709
|
+
}
|
|
710
|
+
async observeStep(input, options) {
|
|
711
|
+
return this.client.observe({
|
|
712
|
+
...executionObserveBase(input),
|
|
713
|
+
input_text: input.input_text ?? `${input.title}\n${input.summary}`,
|
|
714
|
+
execution: executionPayload(input),
|
|
715
|
+
}, {
|
|
716
|
+
...executionScopeOptions(input),
|
|
717
|
+
...(options ?? {}),
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
async handoff(input, options) {
|
|
721
|
+
return this.client.observe({
|
|
722
|
+
...executionObserveBase(input),
|
|
723
|
+
handoff: executionHandoffPayload(input),
|
|
724
|
+
}, {
|
|
725
|
+
...executionScopeOptions(input),
|
|
726
|
+
...(options ?? {}),
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
async guideForRole(input, options) {
|
|
730
|
+
const agentId = executionAgentId(input);
|
|
731
|
+
return this.client.guide({
|
|
732
|
+
query_text: input.query_text,
|
|
733
|
+
agent_role: executionRole(input),
|
|
734
|
+
consumer_agent_id: agentId,
|
|
735
|
+
consumer_team_id: input.team_id,
|
|
736
|
+
run_id: input.run_id,
|
|
737
|
+
context: {
|
|
738
|
+
task_id: input.task_id,
|
|
739
|
+
task_signature: input.task_signature,
|
|
740
|
+
task_family: input.task_family,
|
|
741
|
+
workflow_signature: input.workflow_signature,
|
|
742
|
+
...(input.context ?? {}),
|
|
743
|
+
},
|
|
744
|
+
execution_tree_v1: input.execution_tree_v1 ?? undefined,
|
|
745
|
+
tool_candidates: input.tool_candidates,
|
|
746
|
+
limit: input.limit ?? 10,
|
|
747
|
+
include_packets: input.include_packets ?? true,
|
|
748
|
+
mode: input.mode,
|
|
749
|
+
context_mode: input.context_mode,
|
|
750
|
+
context_char_budget: input.context_char_budget,
|
|
751
|
+
context_token_budget: input.context_token_budget,
|
|
752
|
+
context_compaction_profile: input.context_compaction_profile,
|
|
753
|
+
context_optimization_profile: input.context_optimization_profile,
|
|
754
|
+
...(input.guide ?? {}),
|
|
755
|
+
}, {
|
|
756
|
+
...executionScopeOptions(input),
|
|
757
|
+
...(options ?? {}),
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
async observeOutcome(input, options) {
|
|
761
|
+
const observe = await this.observeStep(input, options);
|
|
762
|
+
const feedback = input.feedback === false ? null : await this.feedbackFromOutcome(input, options);
|
|
763
|
+
return { observe, feedback };
|
|
764
|
+
}
|
|
765
|
+
async feedbackFromOutcome(input, options) {
|
|
766
|
+
const usedMemoryIds = input.used_memory_ids ?? [];
|
|
767
|
+
if (usedMemoryIds.length === 0)
|
|
768
|
+
return null;
|
|
769
|
+
if (input.guide) {
|
|
770
|
+
return this.client.feedback(feedbackFromGuide({
|
|
771
|
+
guide: input.guide,
|
|
772
|
+
reason: input.feedback_reason ?? input.summary,
|
|
773
|
+
run_id: input.run_id,
|
|
774
|
+
outcome: executionFeedbackOutcome(input),
|
|
775
|
+
used_memory_ids: usedMemoryIds,
|
|
776
|
+
used_surface: input.used_surface ?? "use_now",
|
|
777
|
+
actor: input.agent_id,
|
|
778
|
+
verifier_status: executionVerifierStatus(input),
|
|
779
|
+
tool_status: executionToolStatus(input),
|
|
780
|
+
runtime_signal_refs: input.runtime_signal_refs,
|
|
781
|
+
}), {
|
|
782
|
+
...executionScopeOptions(input),
|
|
783
|
+
...(options ?? {}),
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
if (!input.guide_trace_id)
|
|
787
|
+
return null;
|
|
788
|
+
return this.client.feedback({
|
|
789
|
+
target: "memory",
|
|
790
|
+
reason: input.feedback_reason ?? input.summary,
|
|
791
|
+
run_id: input.run_id,
|
|
792
|
+
outcome: executionFeedbackOutcome(input),
|
|
793
|
+
used_surface: input.used_surface ?? "use_now",
|
|
794
|
+
actor: input.agent_id,
|
|
795
|
+
guide_trace_id: input.guide_trace_id,
|
|
796
|
+
used_memory_ids: usedMemoryIds,
|
|
797
|
+
verifier_status: executionVerifierStatus(input),
|
|
798
|
+
tool_status: executionToolStatus(input),
|
|
799
|
+
runtime_signal_refs: input.runtime_signal_refs,
|
|
800
|
+
}, {
|
|
801
|
+
...executionScopeOptions(input),
|
|
802
|
+
...(options ?? {}),
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
async measureRun(input, options) {
|
|
806
|
+
return this.client.measure(measureInputFromGuideLoop({
|
|
807
|
+
task: {
|
|
808
|
+
task_id: input.task_id ?? input.run_id,
|
|
809
|
+
run_id: input.run_id,
|
|
810
|
+
task_signature: input.task_signature,
|
|
811
|
+
task_family: input.task_family,
|
|
812
|
+
},
|
|
813
|
+
before_guide: input.before_guide,
|
|
814
|
+
after_guide: input.after_guide,
|
|
815
|
+
feedback_result: input.feedback_result,
|
|
816
|
+
sufficient_evidence: input.sufficient_evidence,
|
|
817
|
+
evidence_ids: input.evidence_ids,
|
|
818
|
+
tenant_id: input.tenant_id,
|
|
819
|
+
scope: input.scope,
|
|
820
|
+
product_trace: {
|
|
821
|
+
workflow_signature: input.workflow_signature,
|
|
822
|
+
...(input.product_trace ?? {}),
|
|
823
|
+
},
|
|
824
|
+
}), options);
|
|
825
|
+
}
|
|
826
|
+
async snapshotRun(input, options) {
|
|
827
|
+
return this.client.snapshot(snapshotInputFromGuideLoop({
|
|
828
|
+
run_id: input.run_id,
|
|
829
|
+
task_signature: input.task_signature,
|
|
830
|
+
task_family: input.task_family,
|
|
831
|
+
guide: input.guide,
|
|
832
|
+
measure_result: input.measure_result,
|
|
833
|
+
include_markdown: input.include_markdown,
|
|
834
|
+
tenant_id: input.tenant_id,
|
|
835
|
+
scope: input.scope,
|
|
836
|
+
extra: {
|
|
837
|
+
workflow_signature: input.workflow_signature,
|
|
838
|
+
...(input.extra ?? {}),
|
|
839
|
+
},
|
|
840
|
+
}), options);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
194
843
|
export function createAionisClient(options) {
|
|
195
844
|
return new AionisClient(options);
|
|
196
845
|
}
|
|
@@ -208,6 +857,12 @@ export function agentPromptFromGuide(guide) {
|
|
|
208
857
|
}
|
|
209
858
|
return promptText;
|
|
210
859
|
}
|
|
860
|
+
export function rehydrateHintsFromGuide(guide) {
|
|
861
|
+
return rehydrateRequestsFromGuide(guide);
|
|
862
|
+
}
|
|
863
|
+
export function memoryUseReceiptFromGuide(guide) {
|
|
864
|
+
return receiptFromGuideTrace(guide) ?? generatedMemoryUseReceipt(guide);
|
|
865
|
+
}
|
|
211
866
|
export function memoryIdsFromGuide(guide) {
|
|
212
867
|
const context = asRecord(agentContextFromGuide(guide));
|
|
213
868
|
const ids = [
|
|
@@ -216,9 +871,194 @@ export function memoryIdsFromGuide(guide) {
|
|
|
216
871
|
...stringArray(context?.inspect_before_use_memory_ids),
|
|
217
872
|
...stringArray(context?.do_not_use_memory_ids),
|
|
218
873
|
...rehydrateHintMemoryIds(context?.rehydrate_hints),
|
|
874
|
+
...commandPostureArray(context?.command_posture).map((entry) => entry.memory_id),
|
|
875
|
+
...routeContractMemoryIds(context?.route_contract),
|
|
219
876
|
];
|
|
220
877
|
return Array.from(new Set(ids));
|
|
221
878
|
}
|
|
879
|
+
export function routeContractFromGuide(guide) {
|
|
880
|
+
const contract = asRecord(asRecord(agentContextFromGuide(guide))?.route_contract);
|
|
881
|
+
if (!contract)
|
|
882
|
+
return null;
|
|
883
|
+
return {
|
|
884
|
+
active_targets: routeContractActiveTargetArray(contract.active_targets),
|
|
885
|
+
pending_artifacts: routeContractPendingArtifactArray(contract.pending_artifacts),
|
|
886
|
+
reference_only_targets: routeContractTargetArray(contract.reference_only_targets),
|
|
887
|
+
blocked_direction_targets: routeContractTargetArray(contract.blocked_direction_targets),
|
|
888
|
+
evidence_sources: routeContractEvidenceSourceArray(Array.isArray(contract.evidence_sources) ? contract.evidence_sources : contract.reference_only_targets),
|
|
889
|
+
blocked_routes: routeContractBlockedRouteArray(Array.isArray(contract.blocked_routes) ? contract.blocked_routes : contract.blocked_direction_targets),
|
|
890
|
+
conflict_policy: "do_not_treat_missing_active_target_as_superseded",
|
|
891
|
+
fallback_policy: "do_not_promote_reference_or_blocked_targets",
|
|
892
|
+
action_policy: routeContractActionPolicy(contract.action_policy),
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
export function activeRouteTargetsFromGuide(guide) {
|
|
896
|
+
return routeContractFromGuide(guide)?.active_targets.map((entry) => entry.target) ?? [];
|
|
897
|
+
}
|
|
898
|
+
export function pendingArtifactTargetsFromGuide(guide) {
|
|
899
|
+
return routeContractFromGuide(guide)?.pending_artifacts.map((entry) => entry.target) ?? [];
|
|
900
|
+
}
|
|
901
|
+
export function referenceOnlyRouteTargetsFromGuide(guide) {
|
|
902
|
+
return routeContractFromGuide(guide)?.reference_only_targets.map((entry) => entry.target) ?? [];
|
|
903
|
+
}
|
|
904
|
+
export function blockedDirectionRouteTargetsFromGuide(guide) {
|
|
905
|
+
return routeContractFromGuide(guide)?.blocked_direction_targets.map((entry) => entry.target) ?? [];
|
|
906
|
+
}
|
|
907
|
+
export function evidenceSourcesFromGuide(guide) {
|
|
908
|
+
return routeContractFromGuide(guide)?.evidence_sources ?? [];
|
|
909
|
+
}
|
|
910
|
+
export function blockedRoutesFromGuide(guide) {
|
|
911
|
+
return routeContractFromGuide(guide)?.blocked_routes ?? [];
|
|
912
|
+
}
|
|
913
|
+
export function compileExecutionAgentContext(input) {
|
|
914
|
+
const profile = input.budget_profile ?? "balanced";
|
|
915
|
+
const maxPromptChars = input.max_prompt_chars ?? defaultExecutionPromptBudget(profile);
|
|
916
|
+
const basePrompt = safeAgentPromptFromGuide(input.guide);
|
|
917
|
+
const routeContract = routeContractFromGuide(input.guide);
|
|
918
|
+
const commandPosture = commandPostureFromGuide(input.guide);
|
|
919
|
+
const receipt = memoryUseReceiptFromGuide(input.guide);
|
|
920
|
+
const rehydrateRequests = rehydrateHintsFromGuide(input.guide);
|
|
921
|
+
const useNowMemoryIds = receipt.use_now_memory_ids;
|
|
922
|
+
const inspectMemoryIds = receipt.inspect_before_use_memory_ids;
|
|
923
|
+
const doNotUseMemoryIds = receipt.do_not_use_memory_ids;
|
|
924
|
+
const activeTargets = routeContract ? targetList(routeContract.active_targets) : [];
|
|
925
|
+
const pendingArtifacts = routeContract ? targetList(routeContract.pending_artifacts) : [];
|
|
926
|
+
const referenceOnlyTargets = routeContract ? targetList(routeContract.evidence_sources.length > 0
|
|
927
|
+
? routeContract.evidence_sources
|
|
928
|
+
: routeContract.reference_only_targets) : [];
|
|
929
|
+
const blockedDirectionTargets = routeContract ? targetList(routeContract.blocked_routes.length > 0
|
|
930
|
+
? routeContract.blocked_routes
|
|
931
|
+
: routeContract.blocked_direction_targets) : [];
|
|
932
|
+
const presence = repoPresenceMap(input.repo_state);
|
|
933
|
+
const missingActiveTargets = activeTargets.filter((target) => presence.get(target) === false);
|
|
934
|
+
const warnings = [];
|
|
935
|
+
if (missingActiveTargets.length > 0) {
|
|
936
|
+
warnings.push({
|
|
937
|
+
code: "missing_active_target",
|
|
938
|
+
message: "An active route target is absent in the observed workspace; treat it as pending work, not stale memory.",
|
|
939
|
+
targets: missingActiveTargets,
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
if (blockedDirectionTargets.length > 0) {
|
|
943
|
+
warnings.push({
|
|
944
|
+
code: "blocked_route_present",
|
|
945
|
+
message: "Blocked or retired targets are counter-evidence only and must not become the primary route.",
|
|
946
|
+
targets: blockedDirectionTargets,
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
if (referenceOnlyTargets.length > 0) {
|
|
950
|
+
warnings.push({
|
|
951
|
+
code: "reference_only_target_present",
|
|
952
|
+
message: "Reference-only targets may be inspected for evidence but must not be promoted into the chosen route.",
|
|
953
|
+
targets: referenceOnlyTargets,
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
if (rehydrateRequests.length > 0) {
|
|
957
|
+
warnings.push({
|
|
958
|
+
code: "rehydrate_recommended",
|
|
959
|
+
message: "Aionis exposed rehydrate pointers for evidence that should be expanded before exact use.",
|
|
960
|
+
memory_ids: rehydrateRequests.map((entry) => entry.memory_id),
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
const contractSections = [
|
|
964
|
+
"AIONIS_EXECUTION_AGENT_CONTEXT v1",
|
|
965
|
+
"Treat this as the SDK-compiled execution-memory contract. Runtime remains the authority for memory admission.",
|
|
966
|
+
"",
|
|
967
|
+
"TASK",
|
|
968
|
+
...taskLines(input.task),
|
|
969
|
+
...(taskLines(input.task).length === 0 ? ["- Continue the current host task."] : []),
|
|
970
|
+
"",
|
|
971
|
+
"EXECUTION CONTRACT",
|
|
972
|
+
"- Follow active targets and should_continue memories as the current execution route.",
|
|
973
|
+
"- If an active target is missing, treat it as pending work to create or restore when task-consistent; do not fall back to blocked or reference-only paths because they exist.",
|
|
974
|
+
"- Reference-only targets may be read for evidence, but they are not valid primary routes without explicit host confirmation.",
|
|
975
|
+
"- Blocked, must_not, stale, failed, or retired routes are counter-evidence only.",
|
|
976
|
+
"- If compact evidence is insufficient for a precise edit, request rehydrate instead of guessing.",
|
|
977
|
+
...(input.additional_instructions ?? []).map((entry) => `- ${entry}`),
|
|
978
|
+
"",
|
|
979
|
+
"ACTIVE_TARGETS",
|
|
980
|
+
...bulletLines(activeTargets, "none"),
|
|
981
|
+
"",
|
|
982
|
+
"MISSING_ACTIVE_TARGETS",
|
|
983
|
+
...bulletLines(missingActiveTargets, "none observed"),
|
|
984
|
+
"",
|
|
985
|
+
"PENDING_ARTIFACTS",
|
|
986
|
+
...bulletLines(pendingArtifacts, "none"),
|
|
987
|
+
"",
|
|
988
|
+
"SHOULD_CONTINUE",
|
|
989
|
+
...postureLines(commandPosture, "should_continue", "none"),
|
|
990
|
+
"",
|
|
991
|
+
"INSPECT_BEFORE_USE",
|
|
992
|
+
...postureLines(commandPosture, "inspect_first", "none"),
|
|
993
|
+
"",
|
|
994
|
+
"DO_NOT_USE",
|
|
995
|
+
...postureLines(commandPosture, "must_not", "none"),
|
|
996
|
+
"",
|
|
997
|
+
"REFERENCE_ONLY_TARGETS",
|
|
998
|
+
...bulletLines(referenceOnlyTargets, "none"),
|
|
999
|
+
"",
|
|
1000
|
+
"BLOCKED_DIRECTION_TARGETS",
|
|
1001
|
+
...bulletLines(blockedDirectionTargets, "none"),
|
|
1002
|
+
"",
|
|
1003
|
+
"REHYDRATE_REQUESTS",
|
|
1004
|
+
...(rehydrateRequests.length > 0
|
|
1005
|
+
? rehydrateRequests.map((entry) => `- ${entry.memory_id}${entry.reason ? `: ${entry.reason}` : ""}`)
|
|
1006
|
+
: ["- none"]),
|
|
1007
|
+
];
|
|
1008
|
+
const contractPrompt = contractSections.join("\n");
|
|
1009
|
+
const includeBasePrompt = input.include_base_prompt ?? true;
|
|
1010
|
+
const baseHeader = "\n\nBASE_AIONIS_CONTEXT\n";
|
|
1011
|
+
const baseBudget = includeBasePrompt ? Math.max(0, maxPromptChars - contractPrompt.length - baseHeader.length) : 0;
|
|
1012
|
+
const renderedBasePrompt = includeBasePrompt && basePrompt.length > 0 ? truncateText(basePrompt, baseBudget) : "";
|
|
1013
|
+
const agentPrompt = renderedBasePrompt
|
|
1014
|
+
? truncateText(`${contractPrompt}${baseHeader}${renderedBasePrompt}`, maxPromptChars)
|
|
1015
|
+
: truncateText(contractPrompt, maxPromptChars);
|
|
1016
|
+
return {
|
|
1017
|
+
contract_version: "aionis_execution_agent_context_v1",
|
|
1018
|
+
budget_profile: profile,
|
|
1019
|
+
agent_prompt: agentPrompt,
|
|
1020
|
+
base_prompt: basePrompt,
|
|
1021
|
+
prompt_char_count: agentPrompt.length,
|
|
1022
|
+
route_contract: routeContract,
|
|
1023
|
+
command_posture: commandPosture,
|
|
1024
|
+
memory_use_receipt: receipt,
|
|
1025
|
+
rehydrate_requests: rehydrateRequests,
|
|
1026
|
+
use_now_memory_ids: useNowMemoryIds,
|
|
1027
|
+
inspect_before_use_memory_ids: inspectMemoryIds,
|
|
1028
|
+
do_not_use_memory_ids: doNotUseMemoryIds,
|
|
1029
|
+
active_targets: activeTargets,
|
|
1030
|
+
missing_active_targets: missingActiveTargets,
|
|
1031
|
+
pending_artifacts: pendingArtifacts,
|
|
1032
|
+
reference_only_targets: referenceOnlyTargets,
|
|
1033
|
+
blocked_direction_targets: blockedDirectionTargets,
|
|
1034
|
+
execution_warnings: warnings,
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
export function compileCodingAgentContext(input) {
|
|
1038
|
+
return compileExecutionAgentContext(input);
|
|
1039
|
+
}
|
|
1040
|
+
export function commandPostureFromGuide(guide, posture) {
|
|
1041
|
+
const rows = commandPostureArray(asRecord(agentContextFromGuide(guide))?.command_posture);
|
|
1042
|
+
return posture ? rows.filter((entry) => entry.posture === posture) : rows;
|
|
1043
|
+
}
|
|
1044
|
+
export function commandPostureMemoryIdsFromGuide(guide, posture) {
|
|
1045
|
+
return Array.from(new Set(commandPostureFromGuide(guide, posture).map((entry) => entry.memory_id)));
|
|
1046
|
+
}
|
|
1047
|
+
export function mustNotMemoryIdsFromGuide(guide) {
|
|
1048
|
+
return commandPostureMemoryIdsFromGuide(guide, "must_not");
|
|
1049
|
+
}
|
|
1050
|
+
export function shouldContinueMemoryIdsFromGuide(guide) {
|
|
1051
|
+
return commandPostureMemoryIdsFromGuide(guide, "should_continue");
|
|
1052
|
+
}
|
|
1053
|
+
export function inspectFirstMemoryIdsFromGuide(guide) {
|
|
1054
|
+
return commandPostureMemoryIdsFromGuide(guide, "inspect_first");
|
|
1055
|
+
}
|
|
1056
|
+
export function rehydrateFirstMemoryIdsFromGuide(guide) {
|
|
1057
|
+
return commandPostureMemoryIdsFromGuide(guide, "rehydrate_first");
|
|
1058
|
+
}
|
|
1059
|
+
export function optionalContextMemoryIdsFromGuide(guide) {
|
|
1060
|
+
return commandPostureMemoryIdsFromGuide(guide, "optional_context");
|
|
1061
|
+
}
|
|
222
1062
|
export function feedbackFromGuide(input) {
|
|
223
1063
|
const guide = asRecord(input.guide);
|
|
224
1064
|
const guideTraceId = guide?.guide_trace_id;
|