@pal-code/core 0.0.14 → 0.0.15

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.14",
3
+ "version": "0.0.15",
4
4
  "description": "Core runtime for pal — agent loop, providers, tools, sessions",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
package/src/agent/run.ts CHANGED
@@ -656,6 +656,9 @@ async function* agentTurn(opts: RunAgentOptions): AsyncGenerator<AgentRunEvent>
656
656
 
657
657
  // ── No tool calls → turn complete ──
658
658
  if (toolCalls.length === 0) {
659
+ if (!textContent.trim()) {
660
+ console.warn('pal: empty assistant response (no text and no tool calls)');
661
+ }
659
662
  messages.push({role: 'assistant', content: textContent});
660
663
  yield {type: 'done', model, rounds: roundsRun, usage: usage()};
661
664
  return;
package/src/index.ts CHANGED
@@ -108,6 +108,7 @@ export {
108
108
  CORE_TOOLS,
109
109
  getAllTools,
110
110
  registerExtensionTools,
111
+ validateRequiredArgs,
111
112
  clearExtensionTools,
112
113
  getExtensionTools,
113
114
  } from './tools/definitions.js';
@@ -55,10 +55,32 @@ export function clearExtensionTools(): void {
55
55
  }
56
56
 
57
57
  /** The extension tools currently registered (read-only view). */
58
- export function getExtensionTools(): readonly ToolDef[] {
58
+ export function getExtensionTools(): ToolDef[] {
59
59
  return registry.extensionTools;
60
60
  }
61
61
 
62
+ /**
63
+ * Presence check for every `required` argument in the tool's JSON schema.
64
+ * Returns the model-facing error string, or `null` when the call is acceptable.
65
+ *
66
+ * Fail-open by design: an unknown tool is the executor's unknown-tool branch
67
+ * (no schema here to check against), and a schema without `required` has
68
+ * nothing to check. A key present with any value — including `null` — counts
69
+ * as provided; this only catches *absent* keys, e.g. `edit_file` dispatched
70
+ * without `path` (the `ENOENT ... open 'undefined'` failure mode).
71
+ */
72
+ export function validateRequiredArgs(name: string, args: Record<string, unknown>): string | null {
73
+ const params = getAllTools().find((t) => t.function.name === name)?.function.parameters;
74
+ if (!params || !('required' in params)) return null;
75
+ const required: unknown = params.required;
76
+ if (!Array.isArray(required)) return null;
77
+ const missing = required.filter((key) => typeof key === 'string' && args[key] === undefined);
78
+ if (missing.length === 0) return null;
79
+ return missing.length === 1
80
+ ? `missing required argument: ${String(missing[0])}`
81
+ : `missing required argument(s): ${missing.map(String).join(', ')}`;
82
+ }
83
+
62
84
  /**
63
85
  * Get all tools — core tools plus registered extension tools, plus any
64
86
  * explicitly supplied ones (kept for callers that aren't the registry).
@@ -26,6 +26,7 @@ import {snapshotFile} from '../snapshots.js';
26
26
  import {noteEditedFile} from '../diagnostics.js';
27
27
  import type {ConversationMessage} from '../agent/run.js';
28
28
  import {registry} from '../registry.js';
29
+ import {validateRequiredArgs} from './definitions.js';
29
30
 
30
31
  /**
31
32
  * `rg --glob '!pat'` args for each `.pal.json` ignore pattern, so ripgrep
@@ -1077,6 +1078,10 @@ export async function executeTool(
1077
1078
  const args = (
1078
1079
  argsStr && argsStr.trim() ? JSON.parse(argsStr.replaceAll('\u0000', '')) : {}
1079
1080
  ) as Record<string, unknown>;
1081
+ const validationError = validateRequiredArgs(name, args);
1082
+ if (validationError) {
1083
+ return {toolCallId, content: validationError, error: true};
1084
+ }
1080
1085
  const config = loadAgentConfig();
1081
1086
  if (providerConfigOverride) {
1082
1087
  config.provider = providerConfigOverride;