@kolisachint/hoocode-agent 0.4.4 → 0.4.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/CHANGELOG.md +11 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +73 -129
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +11 -1
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +1 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/types.d.ts +4 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +54 -0
- package/dist/core/settings-defaults.d.ts.map +1 -0
- package/dist/core/settings-defaults.js +54 -0
- package/dist/core/settings-defaults.js.map +1 -0
- package/dist/core/settings-manager.d.ts +3 -9
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +41 -45
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/task-store.d.ts +8 -0
- package/dist/core/task-store.d.ts.map +1 -1
- package/dist/core/task-store.js +19 -0
- package/dist/core/task-store.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +6 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/subagent.d.ts +1 -0
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +4 -1
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/task-panel.d.ts +4 -3
- package/dist/modes/interactive/components/task-panel.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-panel.js +9 -12
- package/dist/modes/interactive/components/task-panel.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +15 -8
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +4 -4
|
@@ -1237,6 +1237,57 @@ export class AgentSession {
|
|
|
1237
1237
|
// =========================================================================
|
|
1238
1238
|
// Compaction
|
|
1239
1239
|
// =========================================================================
|
|
1240
|
+
/**
|
|
1241
|
+
* Shared core for manual and auto compaction.
|
|
1242
|
+
*
|
|
1243
|
+
* Runs the `session_before_compact` extension hook, produces the compaction
|
|
1244
|
+
* (from an extension or by summarizing), persists it, updates agent context,
|
|
1245
|
+
* and emits `session_compact`. Returns `{ status: "cancelled" }` if an
|
|
1246
|
+
* extension cancels or the signal aborts; callers map that to their own
|
|
1247
|
+
* cancel handling (manual throws, auto emits).
|
|
1248
|
+
*/
|
|
1249
|
+
async _applyCompaction(params) {
|
|
1250
|
+
const { preparation, branchEntries, model, apiKey, headers, customInstructions, signal } = params;
|
|
1251
|
+
let extensionCompaction;
|
|
1252
|
+
let fromExtension = false;
|
|
1253
|
+
if (this._extensionRunner.hasHandlers("session_before_compact")) {
|
|
1254
|
+
const result = (await this._extensionRunner.emit({
|
|
1255
|
+
type: "session_before_compact",
|
|
1256
|
+
preparation,
|
|
1257
|
+
branchEntries,
|
|
1258
|
+
customInstructions,
|
|
1259
|
+
signal,
|
|
1260
|
+
}));
|
|
1261
|
+
if (result?.cancel) {
|
|
1262
|
+
return { status: "cancelled" };
|
|
1263
|
+
}
|
|
1264
|
+
if (result?.compaction) {
|
|
1265
|
+
extensionCompaction = result.compaction;
|
|
1266
|
+
fromExtension = true;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
const generated = extensionCompaction ??
|
|
1270
|
+
(await compact(preparation, model, apiKey, headers, customInstructions, signal, this.thinkingLevel));
|
|
1271
|
+
if (signal.aborted) {
|
|
1272
|
+
return { status: "cancelled" };
|
|
1273
|
+
}
|
|
1274
|
+
const { summary, firstKeptEntryId, tokensBefore, tokensAfter, details } = generated;
|
|
1275
|
+
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, tokensAfter);
|
|
1276
|
+
const newEntries = this.sessionManager.getEntries();
|
|
1277
|
+
this.agent.state.messages = this.sessionManager.buildSessionContext().messages;
|
|
1278
|
+
const savedCompactionEntry = newEntries.find((e) => e.type === "compaction" && e.summary === summary);
|
|
1279
|
+
if (this._extensionRunner && savedCompactionEntry) {
|
|
1280
|
+
await this._extensionRunner.emit({
|
|
1281
|
+
type: "session_compact",
|
|
1282
|
+
compactionEntry: savedCompactionEntry,
|
|
1283
|
+
fromExtension,
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
return {
|
|
1287
|
+
status: "ok",
|
|
1288
|
+
result: { summary, firstKeptEntryId, tokensBefore, tokensAfter: tokensAfter ?? tokensBefore, details },
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1240
1291
|
/**
|
|
1241
1292
|
* Manually compact the session context.
|
|
1242
1293
|
* Aborts current agent operation first.
|
|
@@ -1263,69 +1314,19 @@ export class AgentSession {
|
|
|
1263
1314
|
}
|
|
1264
1315
|
throw new Error("Nothing to compact (session too small)");
|
|
1265
1316
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
if (result?.cancel) {
|
|
1277
|
-
throw new Error("Compaction cancelled");
|
|
1278
|
-
}
|
|
1279
|
-
if (result?.compaction) {
|
|
1280
|
-
extensionCompaction = result.compaction;
|
|
1281
|
-
fromExtension = true;
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
let summary;
|
|
1285
|
-
let firstKeptEntryId;
|
|
1286
|
-
let tokensBefore;
|
|
1287
|
-
let tokensAfter;
|
|
1288
|
-
let details;
|
|
1289
|
-
if (extensionCompaction) {
|
|
1290
|
-
// Extension provided compaction content
|
|
1291
|
-
summary = extensionCompaction.summary;
|
|
1292
|
-
firstKeptEntryId = extensionCompaction.firstKeptEntryId;
|
|
1293
|
-
tokensBefore = extensionCompaction.tokensBefore;
|
|
1294
|
-
tokensAfter = extensionCompaction.tokensAfter;
|
|
1295
|
-
details = extensionCompaction.details;
|
|
1296
|
-
}
|
|
1297
|
-
else {
|
|
1298
|
-
// Generate compaction result
|
|
1299
|
-
const result = await compact(preparation, this.model, apiKey, headers, customInstructions, this._compactionAbortController.signal, this.thinkingLevel);
|
|
1300
|
-
summary = result.summary;
|
|
1301
|
-
firstKeptEntryId = result.firstKeptEntryId;
|
|
1302
|
-
tokensBefore = result.tokensBefore;
|
|
1303
|
-
tokensAfter = result.tokensAfter;
|
|
1304
|
-
details = result.details;
|
|
1305
|
-
}
|
|
1306
|
-
if (this._compactionAbortController.signal.aborted) {
|
|
1317
|
+
const applied = await this._applyCompaction({
|
|
1318
|
+
preparation,
|
|
1319
|
+
branchEntries: pathEntries,
|
|
1320
|
+
model: this.model,
|
|
1321
|
+
apiKey,
|
|
1322
|
+
headers,
|
|
1323
|
+
customInstructions,
|
|
1324
|
+
signal: this._compactionAbortController.signal,
|
|
1325
|
+
});
|
|
1326
|
+
if (applied.status === "cancelled") {
|
|
1307
1327
|
throw new Error("Compaction cancelled");
|
|
1308
1328
|
}
|
|
1309
|
-
|
|
1310
|
-
const newEntries = this.sessionManager.getEntries();
|
|
1311
|
-
const sessionContext = this.sessionManager.buildSessionContext();
|
|
1312
|
-
this.agent.state.messages = sessionContext.messages;
|
|
1313
|
-
// Get the saved compaction entry for the extension event
|
|
1314
|
-
const savedCompactionEntry = newEntries.find((e) => e.type === "compaction" && e.summary === summary);
|
|
1315
|
-
if (this._extensionRunner && savedCompactionEntry) {
|
|
1316
|
-
await this._extensionRunner.emit({
|
|
1317
|
-
type: "session_compact",
|
|
1318
|
-
compactionEntry: savedCompactionEntry,
|
|
1319
|
-
fromExtension,
|
|
1320
|
-
});
|
|
1321
|
-
}
|
|
1322
|
-
const compactionResult = {
|
|
1323
|
-
summary,
|
|
1324
|
-
firstKeptEntryId,
|
|
1325
|
-
tokensBefore,
|
|
1326
|
-
tokensAfter: tokensAfter ?? tokensBefore,
|
|
1327
|
-
details,
|
|
1328
|
-
};
|
|
1329
|
+
const compactionResult = applied.result;
|
|
1329
1330
|
this._emit({
|
|
1330
1331
|
type: "compaction_end",
|
|
1331
1332
|
reason: "manual",
|
|
@@ -1490,54 +1491,16 @@ export class AgentSession {
|
|
|
1490
1491
|
});
|
|
1491
1492
|
return;
|
|
1492
1493
|
}
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
if (extensionResult?.cancel) {
|
|
1504
|
-
this._emit({
|
|
1505
|
-
type: "compaction_end",
|
|
1506
|
-
reason,
|
|
1507
|
-
result: undefined,
|
|
1508
|
-
aborted: true,
|
|
1509
|
-
willRetry: false,
|
|
1510
|
-
});
|
|
1511
|
-
return;
|
|
1512
|
-
}
|
|
1513
|
-
if (extensionResult?.compaction) {
|
|
1514
|
-
extensionCompaction = extensionResult.compaction;
|
|
1515
|
-
fromExtension = true;
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
let summary;
|
|
1519
|
-
let firstKeptEntryId;
|
|
1520
|
-
let tokensBefore;
|
|
1521
|
-
let tokensAfter;
|
|
1522
|
-
let details;
|
|
1523
|
-
if (extensionCompaction) {
|
|
1524
|
-
// Extension provided compaction content
|
|
1525
|
-
summary = extensionCompaction.summary;
|
|
1526
|
-
firstKeptEntryId = extensionCompaction.firstKeptEntryId;
|
|
1527
|
-
tokensBefore = extensionCompaction.tokensBefore;
|
|
1528
|
-
tokensAfter = extensionCompaction.tokensAfter;
|
|
1529
|
-
details = extensionCompaction.details;
|
|
1530
|
-
}
|
|
1531
|
-
else {
|
|
1532
|
-
// Generate compaction result
|
|
1533
|
-
const compactResult = await compact(preparation, this.model, apiKey, headers, undefined, this._autoCompactionAbortController.signal, this.thinkingLevel);
|
|
1534
|
-
summary = compactResult.summary;
|
|
1535
|
-
firstKeptEntryId = compactResult.firstKeptEntryId;
|
|
1536
|
-
tokensBefore = compactResult.tokensBefore;
|
|
1537
|
-
tokensAfter = compactResult.tokensAfter;
|
|
1538
|
-
details = compactResult.details;
|
|
1539
|
-
}
|
|
1540
|
-
if (this._autoCompactionAbortController.signal.aborted) {
|
|
1494
|
+
const applied = await this._applyCompaction({
|
|
1495
|
+
preparation,
|
|
1496
|
+
branchEntries: pathEntries,
|
|
1497
|
+
model: this.model,
|
|
1498
|
+
apiKey,
|
|
1499
|
+
headers,
|
|
1500
|
+
customInstructions: undefined,
|
|
1501
|
+
signal: this._autoCompactionAbortController.signal,
|
|
1502
|
+
});
|
|
1503
|
+
if (applied.status === "cancelled") {
|
|
1541
1504
|
this._emit({
|
|
1542
1505
|
type: "compaction_end",
|
|
1543
1506
|
reason,
|
|
@@ -1547,26 +1510,7 @@ export class AgentSession {
|
|
|
1547
1510
|
});
|
|
1548
1511
|
return;
|
|
1549
1512
|
}
|
|
1550
|
-
|
|
1551
|
-
const newEntries = this.sessionManager.getEntries();
|
|
1552
|
-
const sessionContext = this.sessionManager.buildSessionContext();
|
|
1553
|
-
this.agent.state.messages = sessionContext.messages;
|
|
1554
|
-
// Get the saved compaction entry for the extension event
|
|
1555
|
-
const savedCompactionEntry = newEntries.find((e) => e.type === "compaction" && e.summary === summary);
|
|
1556
|
-
if (this._extensionRunner && savedCompactionEntry) {
|
|
1557
|
-
await this._extensionRunner.emit({
|
|
1558
|
-
type: "session_compact",
|
|
1559
|
-
compactionEntry: savedCompactionEntry,
|
|
1560
|
-
fromExtension,
|
|
1561
|
-
});
|
|
1562
|
-
}
|
|
1563
|
-
const result = {
|
|
1564
|
-
summary,
|
|
1565
|
-
firstKeptEntryId,
|
|
1566
|
-
tokensBefore,
|
|
1567
|
-
tokensAfter: tokensAfter ?? tokensBefore,
|
|
1568
|
-
details,
|
|
1569
|
-
};
|
|
1513
|
+
const result = applied.result;
|
|
1570
1514
|
this._emit({ type: "compaction_end", reason, result, aborted: false, willRetry });
|
|
1571
1515
|
if (willRetry) {
|
|
1572
1516
|
const messages = this.agent.state.messages;
|