@vincemakes/kiso-core 0.1.2 → 0.1.4

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.
@@ -27,14 +27,14 @@
27
27
  * re-stream that duplicates output or tool calls.
28
28
  */
29
29
  import { isAdapterEvent } from "../protocol/adapter.js";
30
- import { estimateTokens, KEEP_RECENT_TURNS, microcompact } from "./compaction.js";
30
+ import { estimateTokens, microcompact } from "./compaction.js";
31
31
  import { EventLog } from "./event-log.js";
32
32
  import { ToolRegistry } from "../tools/registry.js";
33
33
  import { validateArgs } from "../tools/validate.js";
34
34
  import { NoOpHooks } from "./hooks.js";
35
35
  import { resolveModeProfile } from "./mode.js";
36
36
  import { denialResult } from "./permission.js";
37
- import { messagesToEvents, projectMessages } from "./project.js";
37
+ import { messagesToEvents, MICROCOMPACTABLE, projectMessages } from "./project.js";
38
38
  export const DEFAULT_MAX_TURNS = 10;
39
39
  export const DEFAULT_MAX_RETRIES = 2;
40
40
  export async function* loop(config) {
@@ -797,19 +797,42 @@ function sleep(ms, signal) {
797
797
  });
798
798
  }
799
799
  /**
800
- * C 区: the boundary seq for a microcompact the seq of the user input
801
- * KEEP_RECENT_TURNS+1 places from the end (everything BEFORE that user
802
- * input is old enough to clear; the recent turns stay intact). Undefined
803
- * when the history is too short to clear anything.
800
+ * C (自举 #3): how many of the NEWEST compactable tool results survive a
801
+ * microcompact boundary the model must keep reasoning over the recent
802
+ * results, whatever turn they belong to.
803
+ */
804
+ const KEEP_COMPACTABLE_RESULTS = 4;
805
+ /**
806
+ * C 区: the boundary seq for a microcompact — drawn by COMPACTABLE-RESULT
807
+ * recentness, never user turns: a SINGLE user turn that reads several big
808
+ * files (the coding agent's main overflow shape) crosses the threshold and
809
+ * must trigger. The newest KEEP_COMPACTABLE_RESULTS still-visible
810
+ * compactable tool results stay intact; the boundary points AT the
811
+ * (K+1)th-newest of them, so it and everything older is cleared. Results
812
+ * already cleared by an earlier boundary do not count toward the kept
813
+ * window — each new boundary makes progress. Undefined when fewer than
814
+ * K+1 compactable results remain (the kept window is the whole context).
804
815
  */
805
816
  function microcompactBoundarySeq(events) {
806
- const userSeqs = [];
817
+ const callName = new Map();
818
+ let lastCleared = -1;
819
+ for (const ev of events) {
820
+ if (ev.type === "tool_call_end")
821
+ callName.set(ev.callId, ev.name);
822
+ if (ev.type === "microcompacted" && ev.beforeSeq > lastCleared)
823
+ lastCleared = ev.beforeSeq;
824
+ }
825
+ const visible = [];
807
826
  for (const ev of events) {
808
- if (ev.type === "user_input")
809
- userSeqs.push(ev.seq);
827
+ if (ev.type !== "tool_result" || ev.seq <= lastCleared)
828
+ continue;
829
+ const name = callName.get(ev.callId);
830
+ if (name !== undefined && MICROCOMPACTABLE.has(name))
831
+ visible.push(ev.seq);
810
832
  }
811
- const boundary = userSeqs[userSeqs.length - KEEP_RECENT_TURNS - 1];
812
- return boundary !== undefined ? boundary - 1 : undefined;
833
+ if (visible.length <= KEEP_COMPACTABLE_RESULTS)
834
+ return undefined;
835
+ return visible[visible.length - KEEP_COMPACTABLE_RESULTS - 1];
813
836
  }
814
837
  /** A signal that never aborts — for executions outside any abort scope. */
815
838
  const NEVER_ABORT = {
@@ -22,6 +22,13 @@
22
22
  import type { Event } from "../protocol/events.js";
23
23
  import type { EventInput } from "./event-log.js";
24
24
  import type { AssistantBlock, Message, MessageSource } from "../protocol/messages.js";
25
+ /**
26
+ * C 区: tools whose output is eligible for microcompact clearing — reads,
27
+ * listings, searches, and shell output. write/edit outputs are short and
28
+ * never cleared. Exported so the loop's boundary computation (自举 #3)
29
+ * counts exactly the results the projection can clear.
30
+ */
31
+ export declare const MICROCOMPACTABLE: Set<string>;
25
32
  /** The tag that makes a tool result un-clearable (C 区). */
26
33
  export declare const DO_NOT_COMPACT = "do-not-compact";
27
34
  /**
@@ -22,9 +22,10 @@
22
22
  /**
23
23
  * C 区: tools whose output is eligible for microcompact clearing — reads,
24
24
  * listings, searches, and shell output. write/edit outputs are short and
25
- * never cleared.
25
+ * never cleared. Exported so the loop's boundary computation (自举 #3)
26
+ * counts exactly the results the projection can clear.
26
27
  */
27
- const MICROCOMPACTABLE = new Set(["read_file", "list_dir", "search_text", "shell"]);
28
+ export const MICROCOMPACTABLE = new Set(["read_file", "list_dir", "search_text", "shell"]);
28
29
  /** The tag that makes a tool result un-clearable (C 区). */
29
30
  export const DO_NOT_COMPACT = "do-not-compact";
30
31
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vincemakes/kiso-core",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "kiso(\u57fa\u790e) core \u2014 protocol, event log, loop, hooks, modes, permissions, compaction, delivery truth. The 2,000-line kernel at the bottom of the kiso framework.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  "openai"
34
34
  ],
35
35
  "devDependencies": {
36
- "@vincemakes/kiso-evals": "0.1.2",
36
+ "@vincemakes/kiso-evals": "0.1.4",
37
37
  "@types/node": "^26.1.2",
38
38
  "typescript": "^5.7.2",
39
39
  "vitest": "^3.0.0"