praana 0.5.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.
- package/LICENSE +21 -0
- package/README.md +124 -0
- package/bin/praana.js +17 -0
- package/bin/pran.js +17 -0
- package/dist/app-banner.d.ts +11 -0
- package/dist/app-banner.js +161 -0
- package/dist/app-controller.d.ts +44 -0
- package/dist/app-controller.js +143 -0
- package/dist/app-identity.d.ts +18 -0
- package/dist/app-identity.js +52 -0
- package/dist/auto-compact.d.ts +16 -0
- package/dist/auto-compact.js +101 -0
- package/dist/cli-args.d.ts +14 -0
- package/dist/cli-args.js +69 -0
- package/dist/compile-classic.d.ts +21 -0
- package/dist/compile-classic.js +106 -0
- package/dist/compiler.d.ts +75 -0
- package/dist/compiler.js +406 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.js +433 -0
- package/dist/context-engine/activity-log.d.ts +9 -0
- package/dist/context-engine/activity-log.js +109 -0
- package/dist/context-engine/artifact-store.d.ts +32 -0
- package/dist/context-engine/artifact-store.js +272 -0
- package/dist/context-engine/bm25.d.ts +3 -0
- package/dist/context-engine/bm25.js +32 -0
- package/dist/context-engine/checkpoint.d.ts +34 -0
- package/dist/context-engine/checkpoint.js +430 -0
- package/dist/context-engine/classify.d.ts +3 -0
- package/dist/context-engine/classify.js +60 -0
- package/dist/context-engine/db.d.ts +73 -0
- package/dist/context-engine/db.js +505 -0
- package/dist/context-engine/distiller.d.ts +30 -0
- package/dist/context-engine/distiller.js +67 -0
- package/dist/context-engine/engine-compiler.d.ts +23 -0
- package/dist/context-engine/engine-compiler.js +297 -0
- package/dist/context-engine/error-tracker.d.ts +21 -0
- package/dist/context-engine/error-tracker.js +74 -0
- package/dist/context-engine/event-lineage.d.ts +26 -0
- package/dist/context-engine/event-lineage.js +120 -0
- package/dist/context-engine/extraction.d.ts +26 -0
- package/dist/context-engine/extraction.js +83 -0
- package/dist/context-engine/index.d.ts +82 -0
- package/dist/context-engine/index.js +238 -0
- package/dist/context-engine/scoring.d.ts +13 -0
- package/dist/context-engine/scoring.js +47 -0
- package/dist/context-engine/state-snapshot.d.ts +8 -0
- package/dist/context-engine/state-snapshot.js +50 -0
- package/dist/context-engine/summarize.d.ts +6 -0
- package/dist/context-engine/summarize.js +32 -0
- package/dist/context-engine/telemetry.d.ts +25 -0
- package/dist/context-engine/telemetry.js +64 -0
- package/dist/context-engine/turn-digest.d.ts +50 -0
- package/dist/context-engine/turn-digest.js +250 -0
- package/dist/context-engine/turn-ledger.d.ts +18 -0
- package/dist/context-engine/turn-ledger.js +184 -0
- package/dist/context-engine/turn-recorder.d.ts +24 -0
- package/dist/context-engine/turn-recorder.js +88 -0
- package/dist/context-engine/types.d.ts +201 -0
- package/dist/context-engine/types.js +4 -0
- package/dist/context-pressure.d.ts +19 -0
- package/dist/context-pressure.js +36 -0
- package/dist/distillers/generic.d.ts +14 -0
- package/dist/distillers/generic.js +93 -0
- package/dist/distillers/git-diff.d.ts +8 -0
- package/dist/distillers/git-diff.js +119 -0
- package/dist/distillers/index.d.ts +2 -0
- package/dist/distillers/index.js +16 -0
- package/dist/distillers/npm-test.d.ts +8 -0
- package/dist/distillers/npm-test.js +50 -0
- package/dist/distillers/rg-results.d.ts +8 -0
- package/dist/distillers/rg-results.js +28 -0
- package/dist/distillers/tsc-errors.d.ts +8 -0
- package/dist/distillers/tsc-errors.js +52 -0
- package/dist/event-log.d.ts +56 -0
- package/dist/event-log.js +214 -0
- package/dist/llm.d.ts +29 -0
- package/dist/llm.js +155 -0
- package/dist/logger.d.ts +94 -0
- package/dist/logger.js +287 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +54 -0
- package/dist/memory/confidence.d.ts +7 -0
- package/dist/memory/confidence.js +37 -0
- package/dist/memory/consolidation.d.ts +26 -0
- package/dist/memory/consolidation.js +166 -0
- package/dist/memory/db.d.ts +40 -0
- package/dist/memory/db.js +283 -0
- package/dist/memory/dedup.d.ts +6 -0
- package/dist/memory/dedup.js +50 -0
- package/dist/memory/embedder-factory.d.ts +3 -0
- package/dist/memory/embedder-factory.js +81 -0
- package/dist/memory/embeddings.d.ts +15 -0
- package/dist/memory/embeddings.js +67 -0
- package/dist/memory/index.d.ts +9 -0
- package/dist/memory/index.js +11 -0
- package/dist/memory/ollama-summarizer.d.ts +19 -0
- package/dist/memory/ollama-summarizer.js +72 -0
- package/dist/memory/openai-summarizer.d.ts +21 -0
- package/dist/memory/openai-summarizer.js +51 -0
- package/dist/memory/store.d.ts +61 -0
- package/dist/memory/store.js +502 -0
- package/dist/memory/summarizer-factory.d.ts +3 -0
- package/dist/memory/summarizer-factory.js +69 -0
- package/dist/memory/summarizer.d.ts +4 -0
- package/dist/memory/summarizer.js +112 -0
- package/dist/memory/types.d.ts +87 -0
- package/dist/memory/types.js +17 -0
- package/dist/model-context.d.ts +15 -0
- package/dist/model-context.js +212 -0
- package/dist/project-detector.d.ts +37 -0
- package/dist/project-detector.js +604 -0
- package/dist/render.d.ts +15 -0
- package/dist/render.js +46 -0
- package/dist/session.d.ts +118 -0
- package/dist/session.js +809 -0
- package/dist/skills/index.d.ts +69 -0
- package/dist/skills/index.js +885 -0
- package/dist/skills/types.d.ts +93 -0
- package/dist/skills/types.js +8 -0
- package/dist/slash-commands.d.ts +14 -0
- package/dist/slash-commands.js +301 -0
- package/dist/state-graph.d.ts +38 -0
- package/dist/state-graph.js +255 -0
- package/dist/status-bar.d.ts +54 -0
- package/dist/status-bar.js +184 -0
- package/dist/thinking-display.d.ts +21 -0
- package/dist/thinking-display.js +37 -0
- package/dist/tool-summary.d.ts +4 -0
- package/dist/tool-summary.js +67 -0
- package/dist/tools/index.d.ts +925 -0
- package/dist/tools/index.js +86 -0
- package/dist/tools/knowledge.d.ts +140 -0
- package/dist/tools/knowledge.js +260 -0
- package/dist/tools/memory.d.ts +39 -0
- package/dist/tools/memory.js +300 -0
- package/dist/tools/search-code.d.ts +134 -0
- package/dist/tools/search-code.js +390 -0
- package/dist/tools/system.d.ts +16 -0
- package/dist/tools/system.js +499 -0
- package/dist/tools/tool-def.d.ts +6 -0
- package/dist/tools/tool-def.js +3 -0
- package/dist/turn-control.d.ts +51 -0
- package/dist/turn-control.js +210 -0
- package/dist/turn.d.ts +20 -0
- package/dist/turn.js +624 -0
- package/dist/types.d.ts +233 -0
- package/dist/types.js +4 -0
- package/dist/ui/readline-ui.d.ts +2 -0
- package/dist/ui/readline-ui.js +176 -0
- package/dist/ui/tui/app.d.ts +13 -0
- package/dist/ui/tui/app.js +270 -0
- package/dist/ui/tui/busy-indicator.d.ts +2 -0
- package/dist/ui/tui/busy-indicator.js +13 -0
- package/dist/ui/tui/components/gutter-rule.d.ts +5 -0
- package/dist/ui/tui/components/gutter-rule.js +9 -0
- package/dist/ui/tui/components/inline-tool-row.d.ts +10 -0
- package/dist/ui/tui/components/inline-tool-row.js +8 -0
- package/dist/ui/tui/components/prompt-input.d.ts +20 -0
- package/dist/ui/tui/components/prompt-input.js +120 -0
- package/dist/ui/tui/components/system-line.d.ts +5 -0
- package/dist/ui/tui/components/system-line.js +6 -0
- package/dist/ui/tui/components/thinking-block.d.ts +11 -0
- package/dist/ui/tui/components/thinking-block.js +31 -0
- package/dist/ui/tui/components/toast-line.d.ts +4 -0
- package/dist/ui/tui/components/toast-line.js +8 -0
- package/dist/ui/tui/components/tool-result-line.d.ts +5 -0
- package/dist/ui/tui/components/tool-result-line.js +6 -0
- package/dist/ui/tui/components/turn-footer.d.ts +5 -0
- package/dist/ui/tui/components/turn-footer.js +7 -0
- package/dist/ui/tui/components/user-block.d.ts +6 -0
- package/dist/ui/tui/components/user-block.js +6 -0
- package/dist/ui/tui/logo-banner.d.ts +5 -0
- package/dist/ui/tui/logo-banner.js +8 -0
- package/dist/ui/tui/markdown-render.d.ts +16 -0
- package/dist/ui/tui/markdown-render.js +218 -0
- package/dist/ui/tui/palette.d.ts +12 -0
- package/dist/ui/tui/palette.js +13 -0
- package/dist/ui/tui/reasoning-summary.d.ts +12 -0
- package/dist/ui/tui/reasoning-summary.js +27 -0
- package/dist/ui/tui/reducer.d.ts +92 -0
- package/dist/ui/tui/reducer.js +260 -0
- package/dist/ui/tui/run.d.ts +3 -0
- package/dist/ui/tui/run.js +40 -0
- package/dist/ui/tui/sink.d.ts +4 -0
- package/dist/ui/tui/sink.js +89 -0
- package/dist/ui/tui/status-bar-view.d.ts +5 -0
- package/dist/ui/tui/status-bar-view.js +44 -0
- package/dist/ui/tui/terminal-height.d.ts +12 -0
- package/dist/ui/tui/terminal-height.js +20 -0
- package/dist/ui/tui/terminal-width.d.ts +2 -0
- package/dist/ui/tui/terminal-width.js +5 -0
- package/dist/ui/tui/tool-display.d.ts +23 -0
- package/dist/ui/tui/tool-display.js +217 -0
- package/dist/ui/tui/transcript-line.d.ts +12 -0
- package/dist/ui/tui/transcript-line.js +43 -0
- package/dist/ui/tui/transcript-replay.d.ts +12 -0
- package/dist/ui/tui/transcript-replay.js +117 -0
- package/dist/ui-events.d.ts +39 -0
- package/dist/ui-events.js +33 -0
- package/dist/ui.d.ts +77 -0
- package/dist/ui.js +179 -0
- package/package.json +73 -0
- package/praana.config.example.toml +231 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/** Max gap between Esc presses to count as a double-tap interrupt. */
|
|
2
|
+
export const ESC_INTERRUPT_WINDOW_MS = 600;
|
|
3
|
+
/** Delay before treating a lone ESC byte as a keypress (not an arrow/function prefix). */
|
|
4
|
+
export const ESC_SEQUENCE_DEFER_MS = 30;
|
|
5
|
+
export function nextEscapeInterruptState(lastEscAt, now, windowMs = ESC_INTERRUPT_WINDOW_MS) {
|
|
6
|
+
if (lastEscAt > 0 && now - lastEscAt <= windowMs) {
|
|
7
|
+
return { lastEscAt: 0, triggered: true };
|
|
8
|
+
}
|
|
9
|
+
return { lastEscAt: now, triggered: false };
|
|
10
|
+
}
|
|
11
|
+
function isAnsiFinalByte(byte) {
|
|
12
|
+
return byte >= 0x40 && byte <= 0x7e;
|
|
13
|
+
}
|
|
14
|
+
/** Skip an ANSI/SS3 escape sequence starting at `start` (on the ESC byte). */
|
|
15
|
+
export function skipEscapeSequence(chunk, start) {
|
|
16
|
+
let i = start + 1;
|
|
17
|
+
if (i >= chunk.length)
|
|
18
|
+
return chunk.length;
|
|
19
|
+
const lead = chunk[i];
|
|
20
|
+
if (lead !== 0x5b && lead !== 0x4f)
|
|
21
|
+
return i; // not CSI/SS3
|
|
22
|
+
i++;
|
|
23
|
+
while (i < chunk.length && !isAnsiFinalByte(chunk[i]))
|
|
24
|
+
i++;
|
|
25
|
+
if (i < chunk.length)
|
|
26
|
+
i++;
|
|
27
|
+
return i;
|
|
28
|
+
}
|
|
29
|
+
export function chunkContainsCtrlC(chunk) {
|
|
30
|
+
return chunk.includes(0x03);
|
|
31
|
+
}
|
|
32
|
+
export function consumeEscapeBytes(chunk, lastEscAt, now, windowMs = ESC_INTERRUPT_WINDOW_MS) {
|
|
33
|
+
let last = lastEscAt;
|
|
34
|
+
let triggered = false;
|
|
35
|
+
let deferred = false;
|
|
36
|
+
let i = 0;
|
|
37
|
+
while (i < chunk.length) {
|
|
38
|
+
if (chunk[i] !== 0x1b) {
|
|
39
|
+
i++;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (chunk[i + 1] === 0x1b) {
|
|
43
|
+
triggered = true;
|
|
44
|
+
last = 0;
|
|
45
|
+
i += 2;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (chunk[i + 1] === 0x5b || chunk[i + 1] === 0x4f) {
|
|
49
|
+
i = skipEscapeSequence(chunk, i);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (chunk[i + 1] !== undefined) {
|
|
53
|
+
// Alt/meta combo — not a standalone Esc.
|
|
54
|
+
i += 2;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
deferred = true;
|
|
58
|
+
i++;
|
|
59
|
+
}
|
|
60
|
+
return { lastEscAt: last, triggered, deferred };
|
|
61
|
+
}
|
|
62
|
+
/** Listens for Esc Esc while a turn is running. */
|
|
63
|
+
export class EscInterruptListener {
|
|
64
|
+
lastEscAt = 0;
|
|
65
|
+
dataHandler = null;
|
|
66
|
+
active = false;
|
|
67
|
+
priorRawMode = null;
|
|
68
|
+
rl = null;
|
|
69
|
+
savedWrite = null;
|
|
70
|
+
deferTimer = null;
|
|
71
|
+
onInterrupt = null;
|
|
72
|
+
start(onInterrupt, rl) {
|
|
73
|
+
if (!process.stdin.isTTY || this.active)
|
|
74
|
+
return;
|
|
75
|
+
this.active = true;
|
|
76
|
+
this.lastEscAt = 0;
|
|
77
|
+
this.onInterrupt = onInterrupt;
|
|
78
|
+
this.rl = rl ?? null;
|
|
79
|
+
if (this.rl) {
|
|
80
|
+
this.savedWrite = this.rl.write.bind(this.rl);
|
|
81
|
+
this.rl.write = (() => true);
|
|
82
|
+
this.rl.pause();
|
|
83
|
+
}
|
|
84
|
+
this.priorRawMode = process.stdin.isRaw ?? false;
|
|
85
|
+
process.stdin.setRawMode(true);
|
|
86
|
+
process.stdin.resume();
|
|
87
|
+
this.dataHandler = (chunk) => this.handleData(chunk);
|
|
88
|
+
process.stdin.on("data", this.dataHandler);
|
|
89
|
+
}
|
|
90
|
+
handleData(chunk) {
|
|
91
|
+
if (!this.onInterrupt)
|
|
92
|
+
return;
|
|
93
|
+
if (chunkContainsCtrlC(chunk)) {
|
|
94
|
+
this.clearDeferTimer();
|
|
95
|
+
this.onInterrupt();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (this.deferTimer && chunk.length > 0) {
|
|
99
|
+
const lead = chunk[0];
|
|
100
|
+
if (lead === 0x5b || lead === 0x4f) {
|
|
101
|
+
clearTimeout(this.deferTimer);
|
|
102
|
+
this.deferTimer = null;
|
|
103
|
+
this.consumeAnsiContinuation(chunk);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const now = Date.now();
|
|
108
|
+
const parsed = consumeEscapeBytes(chunk, this.lastEscAt, now);
|
|
109
|
+
this.lastEscAt = parsed.lastEscAt;
|
|
110
|
+
if (parsed.triggered) {
|
|
111
|
+
this.clearDeferTimer();
|
|
112
|
+
this.onInterrupt();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (parsed.deferred) {
|
|
116
|
+
this.clearDeferTimer();
|
|
117
|
+
this.deferTimer = setTimeout(() => {
|
|
118
|
+
this.deferTimer = null;
|
|
119
|
+
if (!this.onInterrupt)
|
|
120
|
+
return;
|
|
121
|
+
const next = nextEscapeInterruptState(this.lastEscAt, Date.now());
|
|
122
|
+
this.lastEscAt = next.lastEscAt;
|
|
123
|
+
if (next.triggered)
|
|
124
|
+
this.onInterrupt();
|
|
125
|
+
}, ESC_SEQUENCE_DEFER_MS);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
consumeAnsiContinuation(chunk) {
|
|
129
|
+
let i = 0;
|
|
130
|
+
while (i < chunk.length) {
|
|
131
|
+
if (chunk[i] === 0x5b || chunk[i] === 0x4f) {
|
|
132
|
+
i++;
|
|
133
|
+
while (i < chunk.length && !isAnsiFinalByte(chunk[i]))
|
|
134
|
+
i++;
|
|
135
|
+
if (i < chunk.length)
|
|
136
|
+
i++;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
i++;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
clearDeferTimer() {
|
|
143
|
+
if (!this.deferTimer)
|
|
144
|
+
return;
|
|
145
|
+
clearTimeout(this.deferTimer);
|
|
146
|
+
this.deferTimer = null;
|
|
147
|
+
}
|
|
148
|
+
stop() {
|
|
149
|
+
if (!this.active)
|
|
150
|
+
return;
|
|
151
|
+
this.active = false;
|
|
152
|
+
this.clearDeferTimer();
|
|
153
|
+
if (this.dataHandler) {
|
|
154
|
+
process.stdin.removeListener("data", this.dataHandler);
|
|
155
|
+
this.dataHandler = null;
|
|
156
|
+
}
|
|
157
|
+
if (process.stdin.isTTY && this.priorRawMode !== null) {
|
|
158
|
+
process.stdin.setRawMode(this.priorRawMode);
|
|
159
|
+
}
|
|
160
|
+
this.priorRawMode = null;
|
|
161
|
+
if (this.rl && this.savedWrite) {
|
|
162
|
+
this.rl.write = this.savedWrite;
|
|
163
|
+
this.savedWrite = null;
|
|
164
|
+
this.rl.resume();
|
|
165
|
+
this.rl = null;
|
|
166
|
+
}
|
|
167
|
+
this.onInterrupt = null;
|
|
168
|
+
this.lastEscAt = 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/** Tracks and aborts the currently running turn (LLM stream / tool execution). */
|
|
172
|
+
export class TurnController {
|
|
173
|
+
controller = null;
|
|
174
|
+
active = false;
|
|
175
|
+
/** Start a new turn; aborts any previous in-flight turn. */
|
|
176
|
+
begin() {
|
|
177
|
+
this.active = true;
|
|
178
|
+
this.controller?.abort();
|
|
179
|
+
this.controller = new AbortController();
|
|
180
|
+
return this.controller.signal;
|
|
181
|
+
}
|
|
182
|
+
/** Whether a turn lifecycle is open (between begin() and end()). */
|
|
183
|
+
isActive() {
|
|
184
|
+
return this.active;
|
|
185
|
+
}
|
|
186
|
+
/** Abort the in-flight turn. No-op if already aborted or ended. */
|
|
187
|
+
abort() {
|
|
188
|
+
if (!this.controller || this.controller.signal.aborted)
|
|
189
|
+
return;
|
|
190
|
+
this.controller.abort();
|
|
191
|
+
}
|
|
192
|
+
get signal() {
|
|
193
|
+
return this.controller?.signal;
|
|
194
|
+
}
|
|
195
|
+
get inProgress() {
|
|
196
|
+
return this.active && this.controller !== null && !this.controller.signal.aborted;
|
|
197
|
+
}
|
|
198
|
+
end() {
|
|
199
|
+
this.active = false;
|
|
200
|
+
this.controller = null;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
export class TurnAbortedError extends Error {
|
|
204
|
+
partialResponse;
|
|
205
|
+
constructor(partialResponse = "") {
|
|
206
|
+
super("Turn interrupted");
|
|
207
|
+
this.name = "TurnAbortedError";
|
|
208
|
+
this.partialResponse = partialResponse;
|
|
209
|
+
}
|
|
210
|
+
}
|
package/dist/turn.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ZodTypeAny } from "zod";
|
|
2
|
+
import type { Session } from "./session.js";
|
|
3
|
+
import type { TurnUiSink } from "./ui-events.js";
|
|
4
|
+
export declare function runTurn(session: Session, userInput: string, modelOverride?: string, options?: {
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
sink?: TurnUiSink;
|
|
7
|
+
}): Promise<string>;
|
|
8
|
+
export declare function isZodSchema(schema: unknown): schema is ZodTypeAny;
|
|
9
|
+
export declare function normalizeToolParameters(schema: unknown): Record<string, unknown>;
|
|
10
|
+
export declare function applyTierManagement(session: Session): void;
|
|
11
|
+
export declare function computeMemoryStats(session: Session, autoHydrated: number, promptTokens?: number, outputTokens?: number): {
|
|
12
|
+
activeState: number;
|
|
13
|
+
totalState: number;
|
|
14
|
+
digestLen: number;
|
|
15
|
+
recallCalls: number;
|
|
16
|
+
recallHits: number;
|
|
17
|
+
autoHydrated: number;
|
|
18
|
+
promptTokens: number;
|
|
19
|
+
outputTokens: number;
|
|
20
|
+
};
|