@project-ava-supernova/core 0.2.92 → 0.2.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/agent.d.ts +24 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +125 -40
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/conversation.d.ts +41 -0
- package/dist/agent/conversation.d.ts.map +1 -1
- package/dist/agent/conversation.js +56 -0
- package/dist/agent/conversation.js.map +1 -1
- package/dist/agent/system-prompt.d.ts.map +1 -1
- package/dist/agent/system-prompt.js +1168 -1166
- package/dist/agent/system-prompt.js.map +1 -1
- package/dist/history/history-manager.d.ts.map +1 -1
- package/dist/history/history-manager.js +4 -0
- package/dist/history/history-manager.js.map +1 -1
- package/dist/history/storage.d.ts +3 -0
- package/dist/history/storage.d.ts.map +1 -1
- package/dist/history/storage.js.map +1 -1
- package/dist/personas/conductor.d.ts.map +1 -1
- package/dist/personas/conductor.js +17 -0
- package/dist/personas/conductor.js.map +1 -1
- package/dist/projects/migrate-layout.d.ts +7 -0
- package/dist/projects/migrate-layout.d.ts.map +1 -1
- package/dist/projects/migrate-layout.js +42 -6
- package/dist/projects/migrate-layout.js.map +1 -1
- package/dist/providers/request-shaping/params.d.ts.map +1 -1
- package/dist/providers/request-shaping/params.js +11 -1
- package/dist/providers/request-shaping/params.js.map +1 -1
- package/package.json +1 -1
package/dist/agent/agent.d.ts
CHANGED
|
@@ -503,6 +503,30 @@ export declare class Agent {
|
|
|
503
503
|
private maybeExplorationBudgetNudge;
|
|
504
504
|
/** Get current context usage for a set of messages. */
|
|
505
505
|
getContextUsage(messages: Message[]): ContextUsage;
|
|
506
|
+
/**
|
|
507
|
+
* Would the next turn compress this context? The same gate runInner uses
|
|
508
|
+
* (70% of the window, capped at 400K, and at least six messages), exposed
|
|
509
|
+
* so a host can compact BETWEEN turns and persist the boundary — see
|
|
510
|
+
* Conversation.applyCompaction. Compacting in the host, before the turn,
|
|
511
|
+
* is what stops the every-turn re-summarising: the agent's own in-turn
|
|
512
|
+
* pass stays as the emergency net for one enormous turn.
|
|
513
|
+
*/
|
|
514
|
+
shouldCompact(messages: Message[]): boolean;
|
|
515
|
+
/**
|
|
516
|
+
* Compact a context and ALSO return the boundary a Conversation can keep:
|
|
517
|
+
* what replaced the head (middle), the note for the system prompt, and
|
|
518
|
+
* where in the input the verbatim tail starts. `result` is the compacted
|
|
519
|
+
* context exactly as compressContext would return it.
|
|
520
|
+
*/
|
|
521
|
+
compact(messages: Message[], onEvent: AgentEventHandler, signal?: AbortSignal): Promise<{
|
|
522
|
+
result: Message[];
|
|
523
|
+
compaction: {
|
|
524
|
+
middle: Message[];
|
|
525
|
+
systemNote: string;
|
|
526
|
+
keptFromContext: number;
|
|
527
|
+
} | null;
|
|
528
|
+
}>;
|
|
529
|
+
private lastCompaction;
|
|
506
530
|
/** Manually compress context — triggered by user clicking the context bar. */
|
|
507
531
|
manualCompress(messages: Message[], onEvent: AgentEventHandler, signal?: AbortSignal): Promise<Message[]>;
|
|
508
532
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agent/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAqC,MAAM,uBAAuB,CAAC;AAEzF,OAAO,KAAK,EACV,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,eAAe,EACf,UAAU,EAEX,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AA+B9D,OAAO,KAAK,EAAE,UAAU,EAAW,MAAM,sBAAsB,CAAC;AA8IhE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,kBAAkB,kQAarB,CAAC;AA2dX;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,IAA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
|
1705
|
-
|
|
1706
|
-
|
|
1703
|
+
// A notice, not an error. This went out on the error channel and every
|
|
1704
|
+
// surface painted it red — three red boxes in one turn on 19 Sep 2026
|
|
1705
|
+
// for a routine trim. `context_truncated` has existed on the event
|
|
1706
|
+
// union with a translated line in 20 languages and nobody emitted it.
|
|
1707
|
+
onEvent({ type: 'context_truncated', droppedCount: dropped });
|
|
1707
1708
|
}
|
|
1708
1709
|
// ── Sanitize messages for model compatibility ──────────────────────────
|
|
1709
1710
|
const filteredMessages = !useNativeTools
|
|
@@ -2902,8 +2903,8 @@ export class Agent {
|
|
|
2902
2903
|
const n = (this.repeatedToolFailures.get(failKey) ?? 0) + 1;
|
|
2903
2904
|
this.repeatedToolFailures.set(failKey, n);
|
|
2904
2905
|
if (n >= 3) {
|
|
2905
|
-
output = `${result.output}
|
|
2906
|
-
|
|
2906
|
+
output = `${result.output}
|
|
2907
|
+
|
|
2907
2908
|
[This is attempt ${n} of \`${toolCall.function.name}\` with identical arguments, and it has failed the same way every time. Do NOT call it again with these arguments — nothing has changed, so nothing will. Tell the user plainly what failed and what the error said, and either change the approach or ask them how they want to proceed.]`;
|
|
2908
2909
|
}
|
|
2909
2910
|
}
|
|
@@ -3118,6 +3119,30 @@ export class Agent {
|
|
|
3118
3119
|
const limit = this.model.contextWindow;
|
|
3119
3120
|
return { used, limit, percent: Math.round((used / limit) * 100) };
|
|
3120
3121
|
}
|
|
3122
|
+
/**
|
|
3123
|
+
* Would the next turn compress this context? The same gate runInner uses
|
|
3124
|
+
* (70% of the window, capped at 400K, and at least six messages), exposed
|
|
3125
|
+
* so a host can compact BETWEEN turns and persist the boundary — see
|
|
3126
|
+
* Conversation.applyCompaction. Compacting in the host, before the turn,
|
|
3127
|
+
* is what stops the every-turn re-summarising: the agent's own in-turn
|
|
3128
|
+
* pass stays as the emergency net for one enormous turn.
|
|
3129
|
+
*/
|
|
3130
|
+
shouldCompact(messages) {
|
|
3131
|
+
const maxInputTokens = Math.min(Math.floor(this.model.contextWindow * 0.7), 400_000);
|
|
3132
|
+
return this.estimateTokenCount(messages) > maxInputTokens && messages.length >= 6;
|
|
3133
|
+
}
|
|
3134
|
+
/**
|
|
3135
|
+
* Compact a context and ALSO return the boundary a Conversation can keep:
|
|
3136
|
+
* what replaced the head (middle), the note for the system prompt, and
|
|
3137
|
+
* where in the input the verbatim tail starts. `result` is the compacted
|
|
3138
|
+
* context exactly as compressContext would return it.
|
|
3139
|
+
*/
|
|
3140
|
+
async compact(messages, onEvent, signal) {
|
|
3141
|
+
this.lastCompaction = null;
|
|
3142
|
+
const result = await this.compressContext(messages, onEvent, signal);
|
|
3143
|
+
return { result, compaction: this.lastCompaction };
|
|
3144
|
+
}
|
|
3145
|
+
lastCompaction = null;
|
|
3121
3146
|
/** Manually compress context — triggered by user clicking the context bar. */
|
|
3122
3147
|
async manualCompress(messages, onEvent, signal) {
|
|
3123
3148
|
return this.compressContext(messages, onEvent, signal);
|
|
@@ -3160,34 +3185,55 @@ export class Agent {
|
|
|
3160
3185
|
// outputs remain in the persisted transcript and are retrievable via
|
|
3161
3186
|
// conversation_recall — the backstop, not the summary, is the place for
|
|
3162
3187
|
// exact tool detail.
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3188
|
+
//
|
|
3189
|
+
// CHUNKED (19 Sep 2026). This used to send the whole compress zone in one
|
|
3190
|
+
// request. At the 400K threshold that is a ~400K-token prompt, which
|
|
3191
|
+
// fails or times out on most models — and the failure was swallowed, so
|
|
3192
|
+
// auto-compression silently never happened and the turn fell through to
|
|
3193
|
+
// truncation, which dropped 115 messages and called it "summarised". Now
|
|
3194
|
+
// the zone is summarised in pieces of at most CHUNK_TOKENS, each into
|
|
3195
|
+
// working notes, and the notes are folded into the one structured
|
|
3196
|
+
// continuation header. A zone that fits in one piece takes one call.
|
|
3197
|
+
const CHUNK_TOKENS = 60_000;
|
|
3198
|
+
const chunks = [];
|
|
3199
|
+
let cur = [];
|
|
3200
|
+
let curTokens = 0;
|
|
3201
|
+
for (const m of toCompress) {
|
|
3202
|
+
const line = `[${m.role}]: ${getTextContent(m.content) || '(no text)'}`;
|
|
3203
|
+
const t = Agent.estimateTextTokens(line);
|
|
3204
|
+
if (cur.length && curTokens + t > CHUNK_TOKENS) {
|
|
3205
|
+
chunks.push(cur.join('\n'));
|
|
3206
|
+
cur = [];
|
|
3207
|
+
curTokens = 0;
|
|
3208
|
+
}
|
|
3209
|
+
cur.push(line);
|
|
3210
|
+
curTokens += t;
|
|
3211
|
+
}
|
|
3212
|
+
if (cur.length)
|
|
3213
|
+
chunks.push(cur.join('\n'));
|
|
3214
|
+
const notesPrompt = (part, total, text) => `You are summarising part ${part} of ${total} of a long transcript between a user and an AI agent, as working notes for a later handoff summary. Capture, as concise bullet points: decisions made, files and functions named, tool results and errors and how they were resolved, what the user asked for in their own words, and what was in flight at the end of this part. No preamble, no narrative.\n\nTRANSCRIPT PART ${part}/${total}:\n${text}`;
|
|
3215
|
+
const compressionPromptFor = (transcript) => `You are a conversation summarizer preparing a handoff for an AI agent that will continue the work. The agent will have zero memory of this transcript except for what you produce, so your summary must be structured and decision-focused, not narrative.
|
|
3216
|
+
|
|
3217
|
+
Produce your output in EXACTLY this format:
|
|
3218
|
+
|
|
3219
|
+
CURRENT_TASK: <one sentence describing what the agent was actively working on at the end of the transcript. This is the single most important field — the agent uses it to decide what to do next. If multiple tasks were interleaved, pick the one that was most recently in flight.>
|
|
3220
|
+
|
|
3221
|
+
LAST_STEP: <one sentence describing the most recent concrete action the agent completed. Example: "Wrote src/components/HabitTracker.tsx with Tauri invoke calls for get_habit_logs."</ >
|
|
3222
|
+
|
|
3223
|
+
NEXT_STEP: <one sentence describing what the agent should do next to continue the task. Example: "Fix the missing habitId argument being passed to get_habit_logs in App.tsx." >
|
|
3224
|
+
|
|
3225
|
+
BLOCKERS: <any active blockers the agent needs to know about. Write "none" if there are none.>
|
|
3226
|
+
|
|
3227
|
+
SUMMARY:
|
|
3228
|
+
<Free-form bullet-point summary of everything else worth preserving: key decisions, file paths, function names, tool results, errors and how they were resolved, technical context. Be thorough but concise. Do NOT repeat what you put in the structured fields above.>
|
|
3229
|
+
|
|
3230
|
+
Rules:
|
|
3231
|
+
- Every field above is MANDATORY. If you can't extract a value for one, write "unclear" but never omit the field.
|
|
3232
|
+
- No pleasantries, no meta-commentary, no "Here's the summary" preamble.
|
|
3233
|
+
- Use plain text in the structured fields — no markdown, no bullet points, no multi-line values.
|
|
3234
|
+
- Keep the CURRENT_TASK, LAST_STEP, NEXT_STEP fields to a single sentence each.
|
|
3235
|
+
|
|
3236
|
+
TRANSCRIPT:
|
|
3191
3237
|
${transcript}`;
|
|
3192
3238
|
// Scale the summary budget to how much is being compressed. A flat cap
|
|
3193
3239
|
// under-summarises a large zone — 1500 tokens for a 300K-token compress
|
|
@@ -3197,19 +3243,25 @@ ${transcript}`;
|
|
|
3197
3243
|
// meant to shrink.
|
|
3198
3244
|
const compressedTokens = this.estimateTokenCount(toCompress);
|
|
3199
3245
|
const summaryBudget = Math.min(4000, Math.max(1500, Math.floor(compressedTokens / 12)));
|
|
3200
|
-
|
|
3246
|
+
const complete = async (prompt, maxTokens, retried = false) => {
|
|
3201
3247
|
const response = await this.provider.createCompletion({
|
|
3202
3248
|
model: this.model.id,
|
|
3203
3249
|
messages: [
|
|
3204
3250
|
{ role: 'system', content: 'You are a precise conversation summarizer.' },
|
|
3205
|
-
{ role: 'user', content:
|
|
3251
|
+
{ role: 'user', content: prompt },
|
|
3206
3252
|
],
|
|
3207
3253
|
// Compression is a real cost the turn incurred, so it belongs to the
|
|
3208
3254
|
// turn. Leaving it untagged would quietly understate what a long
|
|
3209
3255
|
// conversation actually costs to answer.
|
|
3210
3256
|
turnId: this.runTurnId,
|
|
3211
|
-
max_tokens:
|
|
3257
|
+
max_tokens: maxTokens,
|
|
3212
3258
|
temperature: 0.2,
|
|
3259
|
+
// A summary is output, not reasoning. On a thinking model (DeepSeek
|
|
3260
|
+
// V4.1 Flash, Qwen Flash) the reasoning pass ran first and — on a
|
|
3261
|
+
// small budget — the answer came back EMPTY, which this code threw
|
|
3262
|
+
// on, so every in-turn compression fell through to truncation
|
|
3263
|
+
// (19 Sep 2026: "the summary could not be made" on each iteration).
|
|
3264
|
+
enable_thinking: false,
|
|
3213
3265
|
}, signal);
|
|
3214
3266
|
// Meter the compression call. It's a heavy-model completion the same
|
|
3215
3267
|
// shape as a chat turn, just summarising rather than answering a user.
|
|
@@ -3217,7 +3269,34 @@ ${transcript}`;
|
|
|
3217
3269
|
model: this.model.id,
|
|
3218
3270
|
rawTokens: extractUsage(response.usage),
|
|
3219
3271
|
});
|
|
3220
|
-
const
|
|
3272
|
+
const choice = response.choices?.[0];
|
|
3273
|
+
const content = choice?.message?.content || '';
|
|
3274
|
+
if (!content) {
|
|
3275
|
+
// Say WHY it was empty. A cut-off (finish_reason 'length') gets one
|
|
3276
|
+
// more go with double the budget; anything else is reported as is.
|
|
3277
|
+
const usage = response.usage;
|
|
3278
|
+
logger.warn(`[agent] compression: empty reply from ${this.model.id} (finish_reason=${choice?.finish_reason ?? '?'}, prompt=${usage?.prompt_tokens ?? '?'}, completion=${usage?.completion_tokens ?? '?'}, max_tokens=${maxTokens})`);
|
|
3279
|
+
if (choice?.finish_reason === 'length' && !retried)
|
|
3280
|
+
return complete(prompt, maxTokens * 2, true);
|
|
3281
|
+
}
|
|
3282
|
+
return content;
|
|
3283
|
+
};
|
|
3284
|
+
try {
|
|
3285
|
+
let summary;
|
|
3286
|
+
if (chunks.length <= 1) {
|
|
3287
|
+
summary = await complete(compressionPromptFor(chunks[0] ?? ''), summaryBudget);
|
|
3288
|
+
}
|
|
3289
|
+
else {
|
|
3290
|
+
logger.info(`[agent] compression: summarising ${chunks.length} chunks of ≤${CHUNK_TOKENS} tokens`);
|
|
3291
|
+
const notes = [];
|
|
3292
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
3293
|
+
const n = await complete(notesPrompt(i + 1, chunks.length, chunks[i]), 1500);
|
|
3294
|
+
if (!n)
|
|
3295
|
+
throw new Error(`Empty notes for chunk ${i + 1}/${chunks.length}`);
|
|
3296
|
+
notes.push(`--- part ${i + 1}/${chunks.length} ---\n${n}`);
|
|
3297
|
+
}
|
|
3298
|
+
summary = await complete(compressionPromptFor(notes.join('\n\n')), summaryBudget);
|
|
3299
|
+
}
|
|
3221
3300
|
if (!summary)
|
|
3222
3301
|
throw new Error('Empty compression response');
|
|
3223
3302
|
// Memory policy: see notes at the earlier compression site. The
|
|
@@ -3295,6 +3374,9 @@ ${transcript}`;
|
|
|
3295
3374
|
const result = enrichedSystem
|
|
3296
3375
|
? [enrichedSystem, ...middle, ...fixedTail]
|
|
3297
3376
|
: [...middle, ...fixedTail];
|
|
3377
|
+
// The boundary, for a host that keeps its transcript and compacts only
|
|
3378
|
+
// the model's view: the tail starts KEEP_RECENT from the end of the input.
|
|
3379
|
+
this.lastCompaction = { middle, systemNote: pinnedNote, keptFromContext: messages.length - KEEP_RECENT };
|
|
3298
3380
|
const originalTokens = this.estimateTokenCount(messages);
|
|
3299
3381
|
const compressedTokens = this.estimateTokenCount(result);
|
|
3300
3382
|
onEvent({ type: 'context_compression_end', originalTokens, compressedTokens });
|
|
@@ -3306,8 +3388,11 @@ ${transcript}`;
|
|
|
3306
3388
|
});
|
|
3307
3389
|
return result;
|
|
3308
3390
|
}
|
|
3309
|
-
catch {
|
|
3310
|
-
// Compression failed — fall back
|
|
3391
|
+
catch (err) {
|
|
3392
|
+
// Compression failed — fall back (the caller truncates if it must). Not
|
|
3393
|
+
// silently any more: a swallowed failure here is how "auto never
|
|
3394
|
+
// compresses" went undiagnosed.
|
|
3395
|
+
logger.warn(`[agent] compression FAILED (${toCompress.length} messages, ~${compressedTokens} tokens, ${chunks.length} chunk(s)): ${err instanceof Error ? err.message : String(err)}`);
|
|
3311
3396
|
onEvent({ type: 'context_compression_end', originalTokens: 0, compressedTokens: 0 });
|
|
3312
3397
|
return messages;
|
|
3313
3398
|
}
|