@vincemakes/kiso-core 0.1.5 → 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.
@@ -69,6 +69,7 @@ export interface LoopConfig {
69
69
  */
70
70
  readonly microcompact?: {
71
71
  readonly thresholdTokens: number;
72
+ readonly keepResults?: number;
72
73
  };
73
74
  readonly signal?: AbortSignalLike;
74
75
  readonly temperature?: number;
@@ -151,7 +151,7 @@ export async function* loop(config) {
151
151
  }
152
152
  // ── C 区: one-shot microcompact boundary when over the threshold ──
153
153
  if (config.microcompact !== undefined && estimateTokens(messages) > config.microcompact.thresholdTokens) {
154
- const beforeSeq = microcompactBoundarySeq(log.all);
154
+ const beforeSeq = microcompactBoundarySeq(log.all, config.microcompact.keepResults ?? KEEP_COMPACTABLE_RESULTS);
155
155
  if (beforeSeq !== undefined) {
156
156
  const full = log.append({ type: "microcompacted", beforeSeq });
157
157
  if (hooks.onEvent)
@@ -867,23 +867,24 @@ function sleep(ms, signal) {
867
867
  });
868
868
  }
869
869
  /**
870
- * C 区 (自举 #3): how many of the NEWEST compactable tool results survive a
871
- * microcompact boundary the model must keep reasoning over the recent
872
- * results, whatever turn they belong to.
870
+ * C 区 (自举 #3): the DEFAULT for how many of the NEWEST compactable tool
871
+ * results survive a microcompact boundary (overridable per config via
872
+ * microcompact.keepResults) the model must keep reasoning over the
873
+ * recent results, whatever turn they belong to.
873
874
  */
874
875
  const KEEP_COMPACTABLE_RESULTS = 4;
875
876
  /**
876
877
  * C 区: the boundary seq for a microcompact — drawn by COMPACTABLE-RESULT
877
878
  * recentness, never user turns: a SINGLE user turn that reads several big
878
879
  * files (the coding agent's main overflow shape) crosses the threshold and
879
- * must trigger. The newest KEEP_COMPACTABLE_RESULTS still-visible
880
- * compactable tool results stay intact; the boundary points AT the
881
- * (K+1)th-newest of them, so it and everything older is cleared. Results
882
- * already cleared by an earlier boundary do not count toward the kept
883
- * window — each new boundary makes progress. Undefined when fewer than
884
- * K+1 compactable results remain (the kept window is the whole context).
880
+ * must trigger. The newest `keepResults` still-visible compactable tool
881
+ * results stay intact; the boundary points AT the (K+1)th-newest of them,
882
+ * so it and everything older is cleared. Results already cleared by an
883
+ * earlier boundary do not count toward the kept window — each new boundary
884
+ * makes progress. Undefined when fewer than keepResults+1 compactable
885
+ * results remain (the kept window is the whole context).
885
886
  */
886
- function microcompactBoundarySeq(events) {
887
+ function microcompactBoundarySeq(events, keepResults) {
887
888
  const callName = new Map();
888
889
  let lastCleared = -1;
889
890
  for (const ev of events) {
@@ -900,9 +901,9 @@ function microcompactBoundarySeq(events) {
900
901
  if (name !== undefined && MICROCOMPACTABLE.has(name))
901
902
  visible.push(ev.seq);
902
903
  }
903
- if (visible.length <= KEEP_COMPACTABLE_RESULTS)
904
+ if (visible.length <= keepResults)
904
905
  return undefined;
905
- return visible[visible.length - KEEP_COMPACTABLE_RESULTS - 1];
906
+ return visible[visible.length - keepResults - 1];
906
907
  }
907
908
  /** A signal that never aborts — for executions outside any abort scope. */
908
909
  const NEVER_ABORT = {
@@ -39,4 +39,24 @@ export interface KisoExtension {
39
39
  readonly hooks?: HookHost;
40
40
  readonly tools?: readonly Tool[];
41
41
  readonly approvals?: readonly ApprovalPolicy[];
42
+ /**
43
+ * E2: the extension's compaction config — supplies the loop's microcompact
44
+ * parameters (threshold + optional keepResults) when the session config
45
+ * does not set its own microcompact.
46
+ */
47
+ readonly compaction?: {
48
+ readonly thresholdTokens?: number;
49
+ readonly keepResults?: number;
50
+ };
51
+ /**
52
+ * E2: EXTEND the system prompt — append-only, never replace (a replace
53
+ * is a footgun; appends guarantee "adding an extension never removes
54
+ * existing guidance" — the monotonicity family of the approval chain's
55
+ * deny>ask>allow and the veto short-circuit). The session's own
56
+ * systemPrompt comes first, then each extension's append in load order,
57
+ * \n\n-joined.
58
+ */
59
+ readonly systemPrompt?: {
60
+ readonly append: string;
61
+ };
42
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vincemakes/kiso-core",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "kiso(基礎) core — 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.5",
36
+ "@vincemakes/kiso-evals": "0.1.6",
37
37
  "@types/node": "^26.1.2",
38
38
  "typescript": "^5.7.2",
39
39
  "vitest": "^3.0.0"