@hydraharness/harness-compaction 0.1.1-rc.10

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.
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Compaction vocabulary: the result type and the `compaction/*` session events.
3
+ * Those declaration-merged events record the lock and summary inputs without entering the surface, so they are not
4
+ * surface events; a separate replacement `user/message` carries the summary.
5
+ * Backend packages own configuration and retention policy; see
6
+ * `.agents/notes/implemented/feature/2026-06-18-compaction-capability-seam.md`.
7
+ * @module @hydraharness/harness-compaction/types
8
+ */
9
+ import type { ContentBlock, TokenUsage } from '@hydraharness/harness-llm';
10
+ import type { CommandId } from '@hydraharness/harness-commands/brand';
11
+ import type { CompactionId } from './brand.ts';
12
+ export type { CompactionId };
13
+ declare module '@hydraharness/harness-session/types' {
14
+ interface SessionEventMap {
15
+ /**
16
+ * Marks the start of a compaction — log-only, holds the lock until
17
+ * `compaction/end`. A numbered owner is strictly enclosed by that open turn;
18
+ * `null` identifies a standalone manual transaction between turns.
19
+ */
20
+ 'compaction/start': {
21
+ compactionId: CompactionId;
22
+ sourceCommandId?: CommandId;
23
+ turn: number | null;
24
+ };
25
+ /**
26
+ * Completed summary, its inputs, and its model call facts — log-only, no surfaceOp.
27
+ * The summary content is in `data.summary`; the actual surface replacement
28
+ * is performed by the immediately following `user/message` event that
29
+ * shadows the compacted range. That adjacency is contractual — the
30
+ * shadowed pricing fields are the replacement's shadow price, so a
31
+ * consumer may pair a replacement with the metering event directly
32
+ * before it (`compaction/prune` documents the shared protocol).
33
+ */
34
+ 'compaction/summary': {
35
+ compactionId: CompactionId;
36
+ sourceCommandId?: CommandId;
37
+ summary: ContentBlock[];
38
+ shadowedRange: {
39
+ start: number;
40
+ end: number;
41
+ };
42
+ shadowedSeqs: number[];
43
+ shadowedTokenCount: number;
44
+ /** The provider route that wrote the summary. */
45
+ provider: string;
46
+ /**
47
+ * The model that wrote the summary — the summarize call's envelope,
48
+ * reported by the backend that made the call, logged so the one-shot
49
+ * request is reconstructable from log + code and "which model wrote
50
+ * this summary" has a durable answer (the reconstructability Agent Note).
51
+ */
52
+ model: string;
53
+ /** The generation cap the summarize call sent, when one applied. */
54
+ maxTokens?: number;
55
+ /** Provider-reported token usage for the summarization request, when emitted. */
56
+ usage?: TokenUsage;
57
+ } & ({
58
+ /** Complete provider output before the backend's safe summary projection. */
59
+ rawOutput: ContentBlock[];
60
+ /** Identifies exactly one call through this context's `ctx.llm.stream()`. */
61
+ llmStreamCall: true;
62
+ } | {
63
+ /** Optional complete output from an unmarked template, remote, or other summarizer. */
64
+ rawOutput?: ContentBlock[];
65
+ /** An unmarked summary does not identify a call through this context's LLM seam. */
66
+ llmStreamCall?: never;
67
+ });
68
+ /**
69
+ * Marks the end of a compaction — log-only, releases the lock. Its owner
70
+ * matches `compaction/start`; `error` records an unsuccessful attempt.
71
+ */
72
+ 'compaction/end': {
73
+ compactionId: CompactionId;
74
+ sourceCommandId?: CommandId;
75
+ turn: number | null;
76
+ error?: string;
77
+ };
78
+ /**
79
+ * Shadow price of one model-free prune replacement — log-only, no
80
+ * surfaceOp. The shared shadow-price protocol: a surface `replace` event
81
+ * is priced by the metering event immediately before it (`compaction/summary`
82
+ * for a summarizing compaction, this event for a prune), which states the
83
+ * heuristic token price of the exact replaced range so a pure consumer
84
+ * can subtract it without retaining per-node prices. The replacement MUST
85
+ * be appended synchronously right after this event.
86
+ */
87
+ 'compaction/prune': {
88
+ /** The replaced range's first and last surface-node seqs (a surface-position span, like {@link CompactionResult.shadowedRange}). */
89
+ shadowedRange: {
90
+ start: number;
91
+ end: number;
92
+ };
93
+ /** The seqs of all shadowed surface nodes, in surface order. */
94
+ shadowedSeqs: number[];
95
+ /** Heuristic price of the shadowed content under the token-meter's fixed estimator. */
96
+ shadowedTokenCount: number;
97
+ };
98
+ }
99
+ }
100
+ /** Result of a successful compaction operation. */
101
+ export interface CompactionResult {
102
+ /** Stable identity shared by this compaction's complete durable lifecycle. */
103
+ compactionId: CompactionId;
104
+ /** Human command that initiated this compaction, when it was manual. */
105
+ sourceCommandId?: CommandId;
106
+ /** The seq of the appended `compaction/start` event. */
107
+ startSeq: number;
108
+ /** The seq of the appended `compaction/summary` event. */
109
+ summarySeq: number;
110
+ /** The seq of the appended `compaction/end` event. */
111
+ endSeq: number;
112
+ /** The summary content blocks produced by the backend. */
113
+ summary: ContentBlock[];
114
+ /**
115
+ * The surface-boundary pair that was shadowed: the seqs of the first
116
+ * (`start`) and last (`end`) surface nodes of the replaced range. A
117
+ * surface-POSITION span, not a numeric seq interval — after a prior replace
118
+ * lands a fresh high-seq summary node at an older range's position, `start`
119
+ * can be GREATER than `end`. {@link CompactionResult.shadowedSeqs} is the
120
+ * authoritative set of shadowed nodes, in surface order.
121
+ */
122
+ shadowedRange: {
123
+ start: number;
124
+ end: number;
125
+ };
126
+ /** The seqs of all shadowed surface nodes, in surface order. */
127
+ shadowedSeqs: number[];
128
+ /** Estimated token count of the shadowed content. */
129
+ shadowedTokenCount: number;
130
+ }
131
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Compaction vocabulary: the result type and the `compaction/*` session events.
3
+ * Those declaration-merged events record the lock and summary inputs without entering the surface, so they are not
4
+ * surface events; a separate replacement `user/message` carries the summary.
5
+ * Backend packages own configuration and retention policy; see
6
+ * `.agents/notes/implemented/feature/2026-06-18-compaction-capability-seam.md`.
7
+ * @module @hydraharness/harness-compaction/types
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=types.js.map
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@hydraharness/harness-compaction",
3
+ "description": "Abstract compaction service seam (ctx.compaction) for the Hydra harness",
4
+ "version": "0.1.1-rc.10",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/MaiHongPhong2010/Hydra-Harness.git",
11
+ "directory": "packages/compaction/compaction"
12
+ },
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "types": "lib/types/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./lib/types/index.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "./invariant": {
22
+ "types": "./lib/types/invariant.d.ts",
23
+ "default": "./lib/invariant.js"
24
+ },
25
+ "./types": {
26
+ "types": "./lib/types/types.d.ts",
27
+ "default": "./lib/types/types.js"
28
+ },
29
+ "./checkpoint": {
30
+ "types": "./lib/types/checkpoint.d.ts",
31
+ "default": "./lib/types/checkpoint.js"
32
+ },
33
+ "./src/*": "./src/*",
34
+ "./package.json": "./package.json"
35
+ },
36
+ "files": [
37
+ "lib/index.js",
38
+ "lib/invariant.js",
39
+ "lib/types/**/*.js",
40
+ "lib/types/**/*.d.ts"
41
+ ],
42
+ "license": "MIT",
43
+ "peerDependencies": {
44
+ "@hydraharness/harness-commands": "^0.1.1-rc.10",
45
+ "@hydraharness/harness-session": "^0.1.1-rc.10",
46
+ "@hydraharness/harness-llm": "^0.1.1-rc.10",
47
+ "@hydraharness/cordis": "^4.0.2",
48
+ "@hydraharness/harness-brand": "^0.1.1-rc.10",
49
+ "@hydraharness/harness-invariants": "^0.1.1-rc.10"
50
+ },
51
+ "devDependencies": {
52
+ "@hydraharness/harness-brand": "^0.1.1-rc.10",
53
+ "@hydraharness/harness-invariants": "^0.1.1-rc.10",
54
+ "@hydraharness/harness-commands": "^0.1.1-rc.10",
55
+ "@hydraharness/harness-llm": "^0.1.1-rc.10",
56
+ "@hydraharness/harness-session": "^0.1.1-rc.10",
57
+ "@hydraharness/cordis": "^4.0.2"
58
+ }
59
+ }