@pentoshi/clai 2.0.26 → 2.0.28
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/README.md +1 -1
- package/dist/agent/context-manager.d.ts +15 -2
- package/dist/agent/context-manager.js +41 -70
- package/dist/agent/context-manager.js.map +1 -1
- package/dist/agent/events.d.ts +1 -1
- package/dist/agent/runner.d.ts +38 -1
- package/dist/agent/runner.js +719 -135
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/session-title.d.ts +27 -0
- package/dist/agent/session-title.js +109 -0
- package/dist/agent/session-title.js.map +1 -0
- package/dist/commands/update.js +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/llm/http.js +20 -6
- package/dist/llm/http.js.map +1 -1
- package/dist/modes/agent.d.ts +1 -0
- package/dist/modes/agent.js.map +1 -1
- package/dist/modes/ask.d.ts +29 -0
- package/dist/modes/ask.js +188 -23
- package/dist/modes/ask.js.map +1 -1
- package/dist/prompts/index.d.ts +2 -2
- package/dist/prompts/index.js +32 -9
- package/dist/prompts/index.js.map +1 -1
- package/dist/repl.js +104 -3
- package/dist/repl.js.map +1 -1
- package/dist/safety/classifier.js +66 -7
- package/dist/safety/classifier.js.map +1 -1
- package/dist/store/history.js +68 -48
- package/dist/store/history.js.map +1 -1
- package/dist/tools/fs.d.ts +4 -0
- package/dist/tools/fs.js +40 -2
- package/dist/tools/fs.js.map +1 -1
- package/dist/tools/registry.d.ts +8 -0
- package/dist/tools/registry.js +3 -1
- package/dist/tools/registry.js.map +1 -1
- package/dist/tui/App.js +242 -33
- package/dist/tui/App.js.map +1 -1
- package/dist/tui/components/ConfirmModal.js +14 -2
- package/dist/tui/components/ConfirmModal.js.map +1 -1
- package/dist/tui/components/PickerPanel.d.ts +2 -1
- package/dist/tui/components/PickerPanel.js +73 -23
- package/dist/tui/components/PickerPanel.js.map +1 -1
- package/dist/tui/confirm.d.ts +1 -1
- package/dist/tui/confirm.js +8 -0
- package/dist/tui/confirm.js.map +1 -1
- package/dist/tui/hooks/useAgentRunner.d.ts +27 -2
- package/dist/tui/hooks/useAgentRunner.js +149 -18
- package/dist/tui/hooks/useAgentRunner.js.map +1 -1
- package/dist/tui/render-lines.js +28 -1
- package/dist/tui/render-lines.js.map +1 -1
- package/dist/tui/state.d.ts +1 -1
- package/dist/ui/markdown.js +63 -30
- package/dist/ui/markdown.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ clai --classic # start the legacy line-based REPL
|
|
|
59
59
|
CLAI_CLASSIC=1 clai # persistent shell-level opt-out (CLAI_TUI=0 also works)
|
|
60
60
|
|
|
61
61
|
# One-shot ask mode (explains but doesn't execute)
|
|
62
|
-
clai --mode ask "create a python venv and install requests"
|
|
62
|
+
clai --mode ask "how to create a python venv and install requests"
|
|
63
63
|
|
|
64
64
|
# One-shot agent mode (executes)
|
|
65
65
|
clai --mode agent "find all PDFs larger than 10MB in ~/Documents"
|
|
@@ -22,6 +22,16 @@ export interface CompactResult {
|
|
|
22
22
|
afterTokens: number;
|
|
23
23
|
summarized: boolean;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Content prefixes that mark a `role:"system"` message as compacted session
|
|
27
|
+
* memory (vs. the main system prompt or transient injected guidance). Exported
|
|
28
|
+
* so history-persistence can KEEP this memory when it drops other system
|
|
29
|
+
* messages — otherwise a resumed session that compacted mid-run would lose all
|
|
30
|
+
* summarized context.
|
|
31
|
+
*/
|
|
32
|
+
export declare const COMPACTION_MEMORY_PREFIX = "Session memory from compacted earlier turns:";
|
|
33
|
+
export declare const MECHANICAL_MEMORY_PREFIX = "Earlier turns in this session, summarized";
|
|
34
|
+
export declare function isCompactionMemoryMessage(message: ChatMessage): boolean;
|
|
25
35
|
/**
|
|
26
36
|
* Replace older messages with a single condensed "memory" message while
|
|
27
37
|
* preserving the system prompt and the most recent N messages.
|
|
@@ -35,7 +45,10 @@ export interface CompactResult {
|
|
|
35
45
|
export declare function compactMessages(messages: ChatMessage[], options?: CompactOptions): ChatMessage[];
|
|
36
46
|
/**
|
|
37
47
|
* Compact older turns into a model-written memory while retaining recent
|
|
38
|
-
* messages verbatim.
|
|
39
|
-
*
|
|
48
|
+
* messages verbatim. The model summary is the ONLY compaction path: if the
|
|
49
|
+
* model fails to produce a summary we DO NOT fall back to a mechanical dump
|
|
50
|
+
* of the transcript (that historically produced an enormous, low-quality
|
|
51
|
+
* "memory" of tens of thousands of lines). Instead we throw, so the caller
|
|
52
|
+
* can report the failure and the original messages stay untouched.
|
|
40
53
|
*/
|
|
41
54
|
export declare function compactMessagesWithSummary(messages: ChatMessage[], summarize: (prompt: string) => Promise<string>, options?: CompactOptions, sessionTranscript?: string | undefined): Promise<CompactResult>;
|
|
@@ -18,6 +18,20 @@ export function estimateMessagesTokens(messages) {
|
|
|
18
18
|
}
|
|
19
19
|
const DEFAULT_BUDGET_TOKENS = 32_000;
|
|
20
20
|
const DEFAULT_KEEP_RECENT = 12;
|
|
21
|
+
/**
|
|
22
|
+
* Content prefixes that mark a `role:"system"` message as compacted session
|
|
23
|
+
* memory (vs. the main system prompt or transient injected guidance). Exported
|
|
24
|
+
* so history-persistence can KEEP this memory when it drops other system
|
|
25
|
+
* messages — otherwise a resumed session that compacted mid-run would lose all
|
|
26
|
+
* summarized context.
|
|
27
|
+
*/
|
|
28
|
+
export const COMPACTION_MEMORY_PREFIX = "Session memory from compacted earlier turns:";
|
|
29
|
+
export const MECHANICAL_MEMORY_PREFIX = "Earlier turns in this session, summarized";
|
|
30
|
+
export function isCompactionMemoryMessage(message) {
|
|
31
|
+
return (message.role === "system" &&
|
|
32
|
+
(message.content.startsWith(COMPACTION_MEMORY_PREFIX) ||
|
|
33
|
+
message.content.startsWith(MECHANICAL_MEMORY_PREFIX)));
|
|
34
|
+
}
|
|
21
35
|
/**
|
|
22
36
|
* Replace older messages with a single condensed "memory" message while
|
|
23
37
|
* preserving the system prompt and the most recent N messages.
|
|
@@ -62,15 +76,18 @@ export function compactMessages(messages, options = {}) {
|
|
|
62
76
|
}
|
|
63
77
|
const memo = {
|
|
64
78
|
role: "system",
|
|
65
|
-
content:
|
|
79
|
+
content: `${MECHANICAL_MEMORY_PREFIX} to fit the context budget. Full artifacts (when produced) are saved on disk and can be expanded with /output.\n\n` +
|
|
66
80
|
bullets.join("\n"),
|
|
67
81
|
};
|
|
68
82
|
return [...head, memo, ...tail];
|
|
69
83
|
}
|
|
70
84
|
/**
|
|
71
85
|
* Compact older turns into a model-written memory while retaining recent
|
|
72
|
-
* messages verbatim.
|
|
73
|
-
*
|
|
86
|
+
* messages verbatim. The model summary is the ONLY compaction path: if the
|
|
87
|
+
* model fails to produce a summary we DO NOT fall back to a mechanical dump
|
|
88
|
+
* of the transcript (that historically produced an enormous, low-quality
|
|
89
|
+
* "memory" of tens of thousands of lines). Instead we throw, so the caller
|
|
90
|
+
* can report the failure and the original messages stay untouched.
|
|
74
91
|
*/
|
|
75
92
|
export async function compactMessagesWithSummary(messages, summarize, options = {}, sessionTranscript) {
|
|
76
93
|
const before = messages.length;
|
|
@@ -88,6 +105,7 @@ export async function compactMessagesWithSummary(messages, summarize, options =
|
|
|
88
105
|
older = messages.slice(start, tailStart);
|
|
89
106
|
}
|
|
90
107
|
if (older.length === 0 && !sessionTranscript?.trim()) {
|
|
108
|
+
// Genuinely nothing to compact yet — return a no-op result.
|
|
91
109
|
return {
|
|
92
110
|
messages: [...messages],
|
|
93
111
|
before,
|
|
@@ -111,73 +129,26 @@ export async function compactMessagesWithSummary(messages, summarize, options =
|
|
|
111
129
|
"",
|
|
112
130
|
transcript,
|
|
113
131
|
].join("\n");
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
afterTokens: detTokens,
|
|
135
|
-
summarized: false,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
messages: [...messages],
|
|
140
|
-
before,
|
|
141
|
-
after: before,
|
|
142
|
-
beforeTokens,
|
|
143
|
-
afterTokens: beforeTokens,
|
|
144
|
-
summarized: false,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
messages: compacted,
|
|
149
|
-
before,
|
|
150
|
-
after: compacted.length,
|
|
151
|
-
beforeTokens,
|
|
152
|
-
afterTokens,
|
|
153
|
-
summarized: true,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
if (error instanceof Error && (error.name === "AbortError" || error.message?.includes("aborted"))) {
|
|
158
|
-
throw error;
|
|
159
|
-
}
|
|
160
|
-
const compacted = compactMessages(messages, { ...options, budgetTokens: 0 });
|
|
161
|
-
const afterTokens = estimateMessagesTokens(compacted);
|
|
162
|
-
if (afterTokens >= beforeTokens && !isForced) {
|
|
163
|
-
return {
|
|
164
|
-
messages: [...messages],
|
|
165
|
-
before,
|
|
166
|
-
after: before,
|
|
167
|
-
beforeTokens,
|
|
168
|
-
afterTokens: beforeTokens,
|
|
169
|
-
summarized: false,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
return {
|
|
173
|
-
messages: compacted,
|
|
174
|
-
before,
|
|
175
|
-
after: compacted.length,
|
|
176
|
-
beforeTokens,
|
|
177
|
-
afterTokens,
|
|
178
|
-
summarized: false,
|
|
179
|
-
};
|
|
180
|
-
}
|
|
132
|
+
// The summary is the only path. Any failure propagates to the caller —
|
|
133
|
+
// there is deliberately NO deterministic fallback.
|
|
134
|
+
const summary = redactSecrets((await summarize(prompt)).trim());
|
|
135
|
+
if (!summary)
|
|
136
|
+
throw new Error("compaction failed: model returned an empty summary");
|
|
137
|
+
const head = start === 1 ? [messages[0]] : [];
|
|
138
|
+
const compacted = [
|
|
139
|
+
...head,
|
|
140
|
+
{ role: "system", content: `${COMPACTION_MEMORY_PREFIX}\n\n${summary}` },
|
|
141
|
+
...messages.slice(tailStart),
|
|
142
|
+
];
|
|
143
|
+
const afterTokens = estimateMessagesTokens(compacted);
|
|
144
|
+
return {
|
|
145
|
+
messages: compacted,
|
|
146
|
+
before,
|
|
147
|
+
after: compacted.length,
|
|
148
|
+
beforeTokens,
|
|
149
|
+
afterTokens,
|
|
150
|
+
summarized: true,
|
|
151
|
+
};
|
|
181
152
|
}
|
|
182
153
|
function oneLine(text, maxChars) {
|
|
183
154
|
const cleaned = text.replace(/\s+/g, " ").trim();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-manager.js","sourceRoot":"","sources":["../../src/agent/context-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,QAAuB;IAC5D,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,gBAAgB;IAC9D,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAkBD,MAAM,qBAAqB,GAAG,MAAM,CAAC;AACrC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAuB,EACvB,UAA0B,EAAE;IAE5B,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,IAAI,qBAAqB,CAAC;IAC7D,MAAM,UAAU,GAAG,IAAI,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|
|
|
14
14
|
value: boolean;
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
export declare function createSessionPolicy(): SessionPolicy;
|
|
17
|
+
export declare function createSessionPolicy(sessionId?: string): SessionPolicy;
|
|
18
18
|
export interface ConfirmPort {
|
|
19
19
|
confirmTool(call: ToolCall): Promise<boolean>;
|
|
20
20
|
confirmPentest(): Promise<boolean>;
|
|
21
21
|
/** Ask the user whether to continue after hitting the step budget. */
|
|
22
22
|
confirmContinue?(steps: number): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Ask whether to leave ask mode and run an action task in agent mode.
|
|
25
|
+
* Optional so existing ports keep working; ask-mode handoff falls back to a
|
|
26
|
+
* default "no" when a port doesn't implement it.
|
|
27
|
+
*/
|
|
28
|
+
confirmAgentSwitch?(info: {
|
|
29
|
+
reason: string;
|
|
30
|
+
tools: string[];
|
|
31
|
+
}): Promise<boolean>;
|
|
23
32
|
}
|
|
24
33
|
export interface AgentRunOptions {
|
|
25
34
|
provider?: ProviderId | undefined;
|
|
@@ -32,6 +41,14 @@ export interface AgentRunOptions {
|
|
|
32
41
|
onToolStart?: ((call: ToolCall) => void) | undefined;
|
|
33
42
|
onToolResult?: ((call: ToolCall, result: ToolResult) => void) | undefined;
|
|
34
43
|
onEvent?: ((event: AgentEvent) => void) | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Called when a turn ends with the FULL conversation for the turn — the user
|
|
46
|
+
* message, every assistant tool-call, every tool result, and the final
|
|
47
|
+
* answer (system prompts excluded). Callers persist this so a resumed
|
|
48
|
+
* session gives the model back what it actually did (commands, outputs,
|
|
49
|
+
* results), not just its prose answers.
|
|
50
|
+
*/
|
|
51
|
+
onMessages?: ((messages: ChatMessage[]) => void) | undefined;
|
|
35
52
|
confirm?: ConfirmPort | undefined;
|
|
36
53
|
requestSecret?: ((request: {
|
|
37
54
|
title: string;
|
|
@@ -115,6 +132,25 @@ export declare function countToolFences(text: string): number;
|
|
|
115
132
|
export declare function parseAllToolCalls(text: string): ToolCall[];
|
|
116
133
|
/** Structural equality for two tool calls (name + canonical args JSON). */
|
|
117
134
|
export declare function sameToolCall(a: ToolCall, b: ToolCall): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Partition a batch of tool calls (in document order) into execution groups.
|
|
137
|
+
* A run of consecutive parallel-safe calls forms one group to be run
|
|
138
|
+
* concurrently (bounded by maxGroupSize); every non-parallel-safe call is its
|
|
139
|
+
* own single-element group, i.e. a sequential barrier. Because plan updates
|
|
140
|
+
* and side-effecting tools are never parallel-safe, they always split the
|
|
141
|
+
* batch — which keeps parallelism scoped within a single task and prevents
|
|
142
|
+
* plan-state races and overlapping writes.
|
|
143
|
+
*/
|
|
144
|
+
export declare function groupToolCallsForExecution(calls: ToolCall[], isParallelSafe: (call: ToolCall) => boolean, maxGroupSize?: number): ToolCall[][];
|
|
145
|
+
/**
|
|
146
|
+
* Build the conversation to hand back to the caller at turn end. Strips system
|
|
147
|
+
* prompts (they're re-added each turn) but keeps the user turn plus every
|
|
148
|
+
* assistant tool-call and tool result, then appends the final answer if it
|
|
149
|
+
* isn't already the last message. Persisting this is what lets a resumed
|
|
150
|
+
* session give the model back what it actually did — commands, outputs, and
|
|
151
|
+
* results — instead of only its prose answers.
|
|
152
|
+
*/
|
|
153
|
+
export declare function buildTurnHistory(messages: ChatMessage[], answer: string): ChatMessage[];
|
|
118
154
|
/**
|
|
119
155
|
* Collapse pathological repetition before a message is stored in history.
|
|
120
156
|
* Some models degenerate into emitting the same short phrase hundreds of
|
|
@@ -123,6 +159,7 @@ export declare function sameToolCall(a: ToolCall, b: ToolCall): boolean;
|
|
|
123
159
|
* copies and note the collapse so the meaning is preserved without the bulk.
|
|
124
160
|
*/
|
|
125
161
|
export declare function collapseRepeatedText(text: string): string;
|
|
162
|
+
export declare function formatToolArgs(call: ToolCall): string;
|
|
126
163
|
/**
|
|
127
164
|
* Detect pentest/security tasks that need the full step budget.
|
|
128
165
|
* Mirrors looksLikeBuildTask but for security work.
|