@dirgha/code 1.39.0 → 1.40.0
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,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConversationProjection: a derived, in-memory view of session state.
|
|
3
|
+
*
|
|
4
|
+
* The class accepts SessionEntry events (the same shape that
|
|
5
|
+
* SessionStore writes to JSONL) and maintains:
|
|
6
|
+
* - messages: the current Message[] derived from message entries,
|
|
7
|
+
* filtered by the latest compaction threshold
|
|
8
|
+
* - title: the session title (set by the last 'title' entry)
|
|
9
|
+
* - usage: cumulative UsageTotal
|
|
10
|
+
* - compactionThreshold: the keptFrom ts of the latest compaction
|
|
11
|
+
*
|
|
12
|
+
* Two usage patterns:
|
|
13
|
+
* - Replay-based: pass an async iterable of entries to .replayFrom()
|
|
14
|
+
* to bulk-load state from a session JSONL
|
|
15
|
+
* - Live: call .apply(entry) once per new entry to keep the
|
|
16
|
+
* projection in sync with appends
|
|
17
|
+
*
|
|
18
|
+
* This class is read-only from the outside: consumers can only get
|
|
19
|
+
* the current snapshot via getMessages() / getTitle() / getUsage() /
|
|
20
|
+
* getEntries(). The projection itself does NOT write to disk; that
|
|
21
|
+
* remains the Session's responsibility.
|
|
22
|
+
*
|
|
23
|
+
* Not currently used by the agent loop (which keeps its own
|
|
24
|
+
* history array). Provided here so the TUI surface, daemon, and
|
|
25
|
+
* future web-IDE clients can render session state without
|
|
26
|
+
* re-implementing replay logic.
|
|
27
|
+
*/
|
|
28
|
+
import type { Message, UsageTotal } from '../kernel/types.js';
|
|
29
|
+
import type { SessionEntry } from './session.js';
|
|
30
|
+
export declare class ConversationProjection {
|
|
31
|
+
private _messages;
|
|
32
|
+
private _title;
|
|
33
|
+
private _usage;
|
|
34
|
+
private _compactionThreshold;
|
|
35
|
+
private _entries;
|
|
36
|
+
/** Apply a single SessionEntry to this projection. */
|
|
37
|
+
apply(entry: SessionEntry): void;
|
|
38
|
+
/** Bulk-load from an async iterable of entries (e.g. session.replay()). */
|
|
39
|
+
replayFrom(entries: AsyncIterable<SessionEntry>): Promise<void>;
|
|
40
|
+
/** Get all visible messages — those with ts >= compactionThreshold. */
|
|
41
|
+
getMessages(): Message[];
|
|
42
|
+
getTitle(): string | null;
|
|
43
|
+
getUsage(): UsageTotal;
|
|
44
|
+
getCompactionThreshold(): string | null;
|
|
45
|
+
/** Read-only view of the raw entry stream we've ingested. */
|
|
46
|
+
getEntries(): SessionEntry[];
|
|
47
|
+
/** Total message count including pre-compaction entries (audit/debug). */
|
|
48
|
+
rawMessageCount(): number;
|
|
49
|
+
/** Visible message count (post-compaction filter). */
|
|
50
|
+
visibleMessageCount(): number;
|
|
51
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConversationProjection: a derived, in-memory view of session state.
|
|
3
|
+
*
|
|
4
|
+
* The class accepts SessionEntry events (the same shape that
|
|
5
|
+
* SessionStore writes to JSONL) and maintains:
|
|
6
|
+
* - messages: the current Message[] derived from message entries,
|
|
7
|
+
* filtered by the latest compaction threshold
|
|
8
|
+
* - title: the session title (set by the last 'title' entry)
|
|
9
|
+
* - usage: cumulative UsageTotal
|
|
10
|
+
* - compactionThreshold: the keptFrom ts of the latest compaction
|
|
11
|
+
*
|
|
12
|
+
* Two usage patterns:
|
|
13
|
+
* - Replay-based: pass an async iterable of entries to .replayFrom()
|
|
14
|
+
* to bulk-load state from a session JSONL
|
|
15
|
+
* - Live: call .apply(entry) once per new entry to keep the
|
|
16
|
+
* projection in sync with appends
|
|
17
|
+
*
|
|
18
|
+
* This class is read-only from the outside: consumers can only get
|
|
19
|
+
* the current snapshot via getMessages() / getTitle() / getUsage() /
|
|
20
|
+
* getEntries(). The projection itself does NOT write to disk; that
|
|
21
|
+
* remains the Session's responsibility.
|
|
22
|
+
*
|
|
23
|
+
* Not currently used by the agent loop (which keeps its own
|
|
24
|
+
* history array). Provided here so the TUI surface, daemon, and
|
|
25
|
+
* future web-IDE clients can render session state without
|
|
26
|
+
* re-implementing replay logic.
|
|
27
|
+
*/
|
|
28
|
+
export class ConversationProjection {
|
|
29
|
+
_messages = [];
|
|
30
|
+
_title = null;
|
|
31
|
+
_usage = { inputTokens: 0, outputTokens: 0, cachedTokens: 0, costUsd: 0 };
|
|
32
|
+
_compactionThreshold = null;
|
|
33
|
+
_entries = [];
|
|
34
|
+
/** Apply a single SessionEntry to this projection. */
|
|
35
|
+
apply(entry) {
|
|
36
|
+
this._entries.push(entry);
|
|
37
|
+
switch (entry.type) {
|
|
38
|
+
case 'message':
|
|
39
|
+
this._messages.push({ ts: entry.ts, message: entry.message });
|
|
40
|
+
break;
|
|
41
|
+
case 'compaction':
|
|
42
|
+
this._compactionThreshold = entry.keptFrom;
|
|
43
|
+
break;
|
|
44
|
+
case 'title':
|
|
45
|
+
this._title = entry.title;
|
|
46
|
+
break;
|
|
47
|
+
case 'usage':
|
|
48
|
+
this._usage = {
|
|
49
|
+
inputTokens: this._usage.inputTokens + (entry.usage.inputTokens ?? 0),
|
|
50
|
+
outputTokens: this._usage.outputTokens + (entry.usage.outputTokens ?? 0),
|
|
51
|
+
cachedTokens: this._usage.cachedTokens + (entry.usage.cachedTokens ?? 0),
|
|
52
|
+
costUsd: this._usage.costUsd + (entry.usage.costUsd ?? 0),
|
|
53
|
+
};
|
|
54
|
+
break;
|
|
55
|
+
// model_change / branch / system are recorded in _entries but
|
|
56
|
+
// don't update other projection state.
|
|
57
|
+
default:
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Bulk-load from an async iterable of entries (e.g. session.replay()). */
|
|
62
|
+
async replayFrom(entries) {
|
|
63
|
+
for await (const e of entries) {
|
|
64
|
+
this.apply(e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Get all visible messages — those with ts >= compactionThreshold. */
|
|
68
|
+
getMessages() {
|
|
69
|
+
const t = this._compactionThreshold;
|
|
70
|
+
return this._messages
|
|
71
|
+
.filter((m) => !t || m.ts >= t)
|
|
72
|
+
.map((m) => m.message);
|
|
73
|
+
}
|
|
74
|
+
getTitle() {
|
|
75
|
+
return this._title;
|
|
76
|
+
}
|
|
77
|
+
getUsage() {
|
|
78
|
+
return { ...this._usage };
|
|
79
|
+
}
|
|
80
|
+
getCompactionThreshold() {
|
|
81
|
+
return this._compactionThreshold;
|
|
82
|
+
}
|
|
83
|
+
/** Read-only view of the raw entry stream we've ingested. */
|
|
84
|
+
getEntries() {
|
|
85
|
+
return this._entries.slice();
|
|
86
|
+
}
|
|
87
|
+
/** Total message count including pre-compaction entries (audit/debug). */
|
|
88
|
+
rawMessageCount() {
|
|
89
|
+
return this._messages.length;
|
|
90
|
+
}
|
|
91
|
+
/** Visible message count (post-compaction filter). */
|
|
92
|
+
visibleMessageCount() {
|
|
93
|
+
return this.getMessages().length;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../../src/context/projection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAKH,MAAM,OAAO,sBAAsB;IACzB,SAAS,GAA4C,EAAE,CAAC;IACxD,MAAM,GAAkB,IAAI,CAAC;IAC7B,MAAM,GAAe,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACtF,oBAAoB,GAAkB,IAAI,CAAC;IAC3C,QAAQ,GAAmB,EAAE,CAAC;IAEtC,sDAAsD;IACtD,KAAK,CAAC,KAAmB;QACvB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,SAAS;gBACZ,IAAI,CAAC,SAAS,CAAC,IAA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C,EAAE,IAAI,CAAC,CAAC;aAC9B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,QAAQ;QACN,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED,sBAAsB;QACpB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAED,6DAA6D;IAC7D,UAAU;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED,0EAA0E;IAC1E,eAAe;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,sDAAsD;IACtD,mBAAmB;QACjB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC;IACnC,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dirgha/code",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.40.0",
|
|
4
4
|
"description": "CLI coding agent for complex agentic workflows and long-horizon development. Local models (llama.cpp / Ollama), BYOK across 17 providers, parallel agents, persistent memory, scanned skills.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|