Skip to content

Use typescript types for codemode - #3956

Merged
rumpl merged 1 commit into
docker:mainfrom
rumpl:codemode-ts
Aug 10, 2026
Merged

Use typescript types for codemode#3956
rumpl merged 1 commit into
docker:mainfrom
rumpl:codemode-ts

Conversation

@rumpl

@rumpl rumpl commented Aug 9, 2026

Copy link
Copy Markdown
Member

No description provided.

@rumpl
rumpl requested a review from a team as a code owner August 9, 2026 19:42

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟡 NEEDS ATTENTION

Comment thread pkg/tools/codemode/functions.go Outdated
fmt.Fprintf(&doc, "type %s = %s;\n\n", inputName, schemaType(input, input, 0))
}
fmt.Fprintf(&doc, "type %s = %s;\n\n", outputName, schemaType(output, output, 0))
fmt.Fprintf(&doc, "declare function %s(args: %s): %s;\n", tool.Name, inputName, outputName)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] tool.Name used unsanitized in declare function — may produce invalid TypeScript

The declare function line emits tool.Name verbatim, but TypeScript function names must be valid identifiers. If a tool is named with hyphens (e.g. search-items), dots, spaces, or starts with a digit, the output is syntactically invalid TypeScript — declare function search-items(...) would be parsed as a subtraction expression, not a declaration.

baseName (i.e. typeName(tool.Name)) is already computed on line 18 and correctly used for inputName/outputName, but it is not used for the function name itself. The fix is a one-character change:

Suggested change
fmt.Fprintf(&doc, "declare function %s(args: %s): %s;\n", tool.Name, inputName, outputName)
fmt.Fprintf(&doc, "declare function %s(args: %s): %s;\n", baseName, inputName, outputName)
Confidence Score
🟢 strong 100/100

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e6b355b. The declaration now uses the sanitized PascalCase name, and code mode registers the same name in the JavaScript runtime so the advertised function is callable. The original tool name remains registered for compatibility.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed — the fix correctly uses baseName for the function declaration, ensuring tools with non-identifier names (hyphens, dots, etc.) produce valid TypeScript. Registering the sanitized name in the runtime so it's callable is the right approach; maintaining the original name for backward compatibility is a good touch.

Thanks for the quick fix!

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
@aheritier aheritier added area/docs Documentation changes area/tools For features/issues/fixes related to the usage of built-in and MCP tools status/needs-triage For issues that need to be triaged labels Aug 9, 2026
@rumpl
rumpl enabled auto-merge August 9, 2026 20:38
@aheritier aheritier added the kind/refactor PR refactors code without behavior change label Aug 9, 2026
@rumpl
rumpl merged commit 511374b into docker:main Aug 10, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation changes area/tools For features/issues/fixes related to the usage of built-in and MCP tools kind/refactor PR refactors code without behavior change status/needs-triage For issues that need to be triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants