@pal-code/core 0.0.15 → 0.0.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pal-code/core",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "Core runtime for pal — agent loop, providers, tools, sessions",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -11,6 +11,7 @@
11
11
 
12
12
  import {readdirSync} from 'fs';
13
13
  import {join} from 'path';
14
+ import {TOOL_NAME_ALIASES} from '../tools/definitions.js';
14
15
 
15
16
  export interface Frontmatter {
16
17
  /** Keys from the frontmatter block; values are unquoted strings. */
@@ -94,12 +95,16 @@ export function parseToolsValue(value: string): string[] | null {
94
95
  } catch {
95
96
  return null;
96
97
  }
97
- return isStringArray(parsed) ? parsed : null;
98
+ return isStringArray(parsed) ? normalizeToolNames(parsed) : null;
98
99
  }
99
100
 
100
101
  const names = trimmed
101
102
  .split(',')
102
103
  .map((v) => unquote(v.trim()))
103
104
  .filter((v) => v !== '');
104
- return names.length > 0 ? names : null;
105
+ return names.length > 0 ? normalizeToolNames(names) : null;
106
+ }
107
+
108
+ function normalizeToolNames(names: string[]): string[] {
109
+ return names.map((n) => TOOL_NAME_ALIASES[n] ?? n);
105
110
  }
package/src/agent/run.ts CHANGED
@@ -25,6 +25,10 @@ export interface UserMsg {
25
25
  export interface AssistantMsg {
26
26
  role: 'assistant';
27
27
  content: string;
28
+ /** Model thinking text — display-only, never sent back to the provider. */
29
+ thinking?: string;
30
+ /** Thinking-phase elapsed ms, for the resume label. */
31
+ thinkingMs?: number;
28
32
  toolCalls?: Array<{
29
33
  id: string;
30
34
  name: string;
@@ -93,6 +97,7 @@ export type AgentRunEvent =
93
97
  | {type: 'model-start'; model: string}
94
98
  | {type: 'round-start'; round: number; max: number}
95
99
  | {type: 'text-delta'; content: string}
100
+ | {type: 'thinking-delta'; content: string}
96
101
  | {type: 'tool-start'; id: string; name: string; argsSummary: string}
97
102
  | {type: 'tool-end'; id: string; name: string; ok: boolean; content: string; ms: number}
98
103
  | {type: 'notice'; text: string}
@@ -135,7 +140,7 @@ export interface RunAgentOptions {
135
140
  * one).
136
141
  */
137
142
  budget?: {roleName: string; limit: number};
138
- /** Context window used to decide when to compact (default 100_000). */
143
+ /** Context window used to decide when to compact (default 200_000). */
139
144
  contextLimit?: number;
140
145
  /** Reasoning effort forwarded to the provider (default 'medium'). */
141
146
  reasoningEffort?: 'low' | 'medium' | 'high';
@@ -192,7 +197,7 @@ export interface RunAgentOptions {
192
197
  const REPEAT_WARN = 3;
193
198
  const REPEAT_STOP = 6;
194
199
  const DEFAULT_MAX_ROUNDS = 100;
195
- const DEFAULT_CONTEXT_LIMIT = 100_000;
200
+ const DEFAULT_CONTEXT_LIMIT = 200_000;
196
201
  const RESERVED_TOKENS = 12_000;
197
202
  /** Recent messages always kept verbatim when compacting. */
198
203
  const KEEP_RECENT = 5;
@@ -219,11 +224,11 @@ Response must include:
219
224
 
220
225
  /** Tools that only read — safe to run concurrently. */
221
226
  const PARALLEL_SAFE = new Set([
222
- 'read_file',
223
- 'list_directory',
227
+ 'read',
228
+ 'ls',
224
229
  'grep',
225
230
  'grep_search',
226
- 'glob_search',
231
+ 'glob',
227
232
  'ast_grep',
228
233
  'repo_map',
229
234
  ]);
@@ -243,9 +248,9 @@ function truncate(text: string, max: number): string {
243
248
  export function summarizeArgs(name: string, args: Record<string, unknown>): string {
244
249
  const v = (key: string) => String(args[key] ?? '');
245
250
  switch (name) {
246
- case 'read_file':
247
- case 'write_file':
248
- case 'edit_file': {
251
+ case 'read':
252
+ case 'write':
253
+ case 'edit': {
249
254
  const fp = v('path') || v('file') || v('file_path') || v('filePath');
250
255
  return fp.split(/[/\\]/).pop() || truncate(fp, 40);
251
256
  }
@@ -253,7 +258,7 @@ export function summarizeArgs(name: string, args: Record<string, unknown>): stri
253
258
  return truncate(v('command') || v('cmd'), 40);
254
259
  case 'grep':
255
260
  return v('pattern') || v('query') || truncate(v('regex'), 40);
256
- case 'list_directory':
261
+ case 'ls':
257
262
  return v('path') || v('directory');
258
263
  case 'glob':
259
264
  return v('pattern') || v('glob');
@@ -620,8 +625,11 @@ async function* agentTurn(opts: RunAgentOptions): AsyncGenerator<AgentRunEvent>
620
625
  }
621
626
  }
622
627
 
623
- const apiMessages = buildApiMessages(messages, systemPrompt, compactionNote, compactedUpto);
624
- let textContent = '';
628
+ const apiMessages = buildApiMessages(messages, systemPrompt, compactionNote, compactedUpto);
629
+ let textContent = '';
630
+ let thinkingContent = '';
631
+ let thinkingStart: number | null = null;
632
+ let thinkingMs: number | null = null;
625
633
  const toolCalls: NonNullable<AssistantMsg['toolCalls']> = [];
626
634
 
627
635
  try {
@@ -633,8 +641,13 @@ async function* agentTurn(opts: RunAgentOptions): AsyncGenerator<AgentRunEvent>
633
641
  ...getEffortParams(model, reasoningEffort),
634
642
  } as never) as AsyncGenerator<StreamEvent>) {
635
643
  if (event.type === 'text' && event.content) {
644
+ if (thinkingMs === null && thinkingStart !== null) thinkingMs = Date.now() - thinkingStart;
636
645
  textContent += event.content;
637
646
  yield {type: 'text-delta', content: event.content};
647
+ } else if (event.type === 'thinking' && event.content) {
648
+ if (thinkingStart === null) thinkingStart = Date.now();
649
+ thinkingContent += event.content;
650
+ yield {type: 'thinking-delta', content: event.content};
638
651
  } else if (event.type === 'tool_use' && event.toolCall) {
639
652
  toolCalls.push(event.toolCall);
640
653
  } else if (event.type === 'error') {
@@ -655,16 +668,20 @@ async function* agentTurn(opts: RunAgentOptions): AsyncGenerator<AgentRunEvent>
655
668
  }
656
669
 
657
670
  // ── No tool calls → turn complete ──
671
+ if (thinkingMs === null && thinkingStart !== null) thinkingMs = Date.now() - thinkingStart;
672
+ const thinkingMeta = thinkingContent
673
+ ? {thinking: thinkingContent, thinkingMs: thinkingMs ?? 0}
674
+ : {};
658
675
  if (toolCalls.length === 0) {
659
676
  if (!textContent.trim()) {
660
677
  console.warn('pal: empty assistant response (no text and no tool calls)');
661
678
  }
662
- messages.push({role: 'assistant', content: textContent});
679
+ messages.push({role: 'assistant', content: textContent, ...thinkingMeta});
663
680
  yield {type: 'done', model, rounds: roundsRun, usage: usage()};
664
681
  return;
665
682
  }
666
683
 
667
- messages.push({role: 'assistant', content: textContent, toolCalls});
684
+ messages.push({role: 'assistant', content: textContent, toolCalls, ...thinkingMeta});
668
685
 
669
686
  const displays = toolCalls.map((tc) => {
670
687
  let argsSummary = '';
@@ -810,6 +827,8 @@ async function* agentTurn(opts: RunAgentOptions): AsyncGenerator<AgentRunEvent>
810
827
  yield {type: 'round-start', round: roundsRun + 1, max: roundsRun + 1};
811
828
 
812
829
  let wrapText = '';
830
+ let wrapThinking = '';
831
+ let wrapThinkingStart: number | null = null;
813
832
  try {
814
833
  for await (const event of provider.stream({
815
834
  model,
@@ -821,6 +840,10 @@ async function* agentTurn(opts: RunAgentOptions): AsyncGenerator<AgentRunEvent>
821
840
  if (event.type === 'text' && event.content) {
822
841
  wrapText += event.content;
823
842
  yield {type: 'text-delta', content: event.content};
843
+ } else if (event.type === 'thinking' && event.content) {
844
+ if (wrapThinkingStart === null) wrapThinkingStart = Date.now();
845
+ wrapThinking += event.content;
846
+ yield {type: 'thinking-delta', content: event.content};
824
847
  } else if (event.type === 'done' && event.usage) {
825
848
  totalInput += event.usage.promptTokens ?? 0;
826
849
  totalOutput += event.usage.completionTokens ?? 0;
@@ -838,7 +861,17 @@ async function* agentTurn(opts: RunAgentOptions): AsyncGenerator<AgentRunEvent>
838
861
  text: `! wrap-up failed: ${err instanceof Error ? err.message : String(err)}`,
839
862
  };
840
863
  }
841
- if (wrapText) messages.push({role: 'assistant', content: wrapText});
864
+ if (wrapText)
865
+ messages.push({
866
+ role: 'assistant',
867
+ content: wrapText,
868
+ ...(wrapThinking
869
+ ? {
870
+ thinking: wrapThinking,
871
+ thinkingMs: wrapThinkingStart !== null ? Date.now() - wrapThinkingStart : 0,
872
+ }
873
+ : {}),
874
+ });
842
875
  }
843
876
 
844
877
  yield {type: 'done', model, rounds: roundsRun, usage: usage()};
package/src/compaction.ts CHANGED
@@ -22,7 +22,7 @@ export function estimateTokens(text: string): number {
22
22
  export function estimateMessagesTokens(messages: CompactableMessage[]): number {
23
23
  return messages.reduce((sum, m) => {
24
24
  let tokens = estimateTokens(m.content || '') + 4;
25
- // Count tool-call arguments — a transcript dominated by large write_file
25
+ // Count tool-call arguments — a transcript dominated by large write
26
26
  // bodies or long bash commands would otherwise under-count massively.
27
27
  if (m.toolCalls) {
28
28
  for (const tc of m.toolCalls) {
package/src/config.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  import {readFileSync, statSync} from 'fs';
10
10
  import {resolve, relative, isAbsolute, basename} from 'path';
11
11
  import {minimatch} from 'minimatch';
12
+ import {TOOL_NAME_ALIASES} from './tools/definitions.js';
12
13
 
13
14
  /** Config file schema. */
14
15
  export interface ToolConfig {
@@ -16,9 +17,9 @@ export interface ToolConfig {
16
17
  ignore: string[];
17
18
  /** Whether to skip files larger than maxFileSizeKB. */
18
19
  ignoreLargeFiles: boolean;
19
- /** Max file size in KB for read_file (default: 512). */
20
+ /** Max file size in KB for read (default: 512). */
20
21
  maxFileSizeKB: number;
21
- /** Max lines to return from read_file (default: 2000). */
22
+ /** Max lines to return from read (default: 2000). */
22
23
  readLineLimit: number;
23
24
  /** Provider config for delegate tool — set by CLI to pass model/key to child agents. */
24
25
  provider?: {
@@ -127,15 +128,15 @@ export const BUILTIN_SENSITIVE_RULES: PermissionRule[] = [
127
128
 
128
129
  /** Built-in default actions per tool. */
129
130
  export const BUILTIN_PERMISSION_DEFAULTS: Record<string, 'allow' | 'ask' | 'deny'> = {
130
- read_file: 'allow',
131
- write_file: 'allow',
132
- edit_file: 'allow',
131
+ read: 'allow',
132
+ write: 'allow',
133
+ edit: 'allow',
133
134
  edit_block: 'allow',
134
135
  bash: 'allow',
135
- list_directory: 'allow',
136
+ ls: 'allow',
136
137
  grep: 'allow',
137
138
  grep_search: 'allow',
138
- glob_search: 'allow',
139
+ glob: 'allow',
139
140
  ast_grep: 'allow',
140
141
  repo_map: 'allow',
141
142
  delegate: 'allow',
@@ -215,12 +216,23 @@ export function loadPermissionConfig(cwd?: string): PermissionConfig {
215
216
 
216
217
  // Merge user defaults (override built-in defaults)
217
218
  if (parsed.defaults && typeof parsed.defaults === 'object') {
218
- Object.assign(config.defaults, parsed.defaults);
219
+ for (const [tool, action] of Object.entries(parsed.defaults)) {
220
+ if (action === 'allow' || action === 'ask' || action === 'deny') {
221
+ config.defaults[TOOL_NAME_ALIASES[tool] ?? tool] = action;
222
+ }
223
+ }
219
224
  }
220
225
 
221
226
  // Append user rules (after built-in rules, so built-ins match first)
222
227
  if (Array.isArray(parsed.rules)) {
223
- config.rules.push(...parsed.rules);
228
+ config.rules.push(
229
+ ...parsed.rules.map((rule: PermissionRule) => ({
230
+ ...rule,
231
+ tool: Array.isArray(rule.tool)
232
+ ? rule.tool.map((t) => TOOL_NAME_ALIASES[t] ?? t)
233
+ : TOOL_NAME_ALIASES[rule.tool] ?? rule.tool,
234
+ })),
235
+ );
224
236
  }
225
237
 
226
238
  return config;
@@ -430,7 +442,7 @@ export function checkFileSize(filePath: string, config: ToolConfig): string | nu
430
442
  const st = statSync(filePath);
431
443
  const sizeKB = st.size / 1024;
432
444
  if (sizeKB > config.maxFileSizeKB) {
433
- return `File too large (${Math.round(sizeKB)}KB > ${config.maxFileSizeKB}KB limit). Use read_file with offset/limit to read sections.`;
445
+ return `File too large (${Math.round(sizeKB)}KB > ${config.maxFileSizeKB}KB limit). Use read with offset/limit to read sections.`;
434
446
  }
435
447
  } catch {
436
448
  // File doesn't exist — let the tool handle that error