[#1] feat: extract Tool class + lib/tool/ modules into src/#9
Conversation
Greptile SummaryThis PR extracts the
Confidence Score: 5/5Safe to merge — the core dispatch pipeline, error envelopes, and schema validation are all correct; the only findings are defensive hardening suggestions for the output-helper spread order. The extraction is clean: imports are correctly re-pointed, the Zod v4 API is used correctly, and all 15 smoke tests pass. The spread-order issue in the output helpers only manifests when a caller passes a key that collides with an envelope field, and would surface immediately as a schema_violation at runtime. src/output-helpers.ts — spread order in l1Output, l2Output, and l3Output should be reviewed.
|
| Filename | Overview |
|---|---|
| src/tool-class.ts | Core Tool orchestrator with invoke/run dispatch pipeline. Handler-execution block is duplicated between invoke and runSubcommand (flagged previously). Logic is otherwise sound. |
| src/output-helpers.ts | Level-specific output schema composers. Spread order places ...fields last, allowing user-provided keys to silently override the required envelope fields. |
| src/args.ts | Pure argv parser with global-flag override for reserved subcommands. Logic is correct and well-documented. |
| src/envelopes.ts | Error envelope factories covering all error codes. Discriminated union is well-typed; ToolError correctly extends Error. |
| tsconfig.json | Added allowImportingTsExtensions + noEmit. The noEmit:true/types:./dist/index.d.ts conflict is acknowledged via TODO comment but leaves typed consumers broken until a tsconfig.build.json is added. |
| package.json | Renamed to @code-first-agents/tool, added zod@^4.0.0. The exports map references dist/index.d.ts which won't be produced by the current build setup. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Tool.run(argv)"] --> B["parseArgs(argv)"]
B --> C{"dispatchBuiltin?"}
C -- "schema/help" --> D["jsonOutput(builtin)"]
C -- "null" --> E{"rejectUnknown?"}
E -- "unknown_subcommand" --> F["jsonOutput(error)"]
E -- "null" --> G["runSubcommand(name, parsed)"]
G --> H["validateInput(parsed, spec.input)"]
H -- "fail" --> I["inputValidationErrorEnvelope"]
H -- "ok" --> J["await spec.handler(data)"]
J -- "throws ToolError" --> K["toolErrorEnvelope"]
J -- "throws Error" --> L["unexpectedErrorEnvelope"]
J -- "plain object" --> N["stamp ok: true"]
N --> O["spec.output.safeParse(result)"]
O -- "fail" --> P["schemaViolationEnvelope"]
O -- "pass" --> Q["jsonOutput(success)"]
Reviews (3): Last reviewed commit: "fix: update package name in JSDoc + biom..." | Re-trigger Greptile
Copy 7 modules from kael.factory lib/tool/ into standalone package src/: types, args, json-schema, output-helpers, introspection, envelopes, tool-class. Create lean src/utils.ts with ToolOutput, jsonOutput, stringifyError. Add zod v4 as production dependency. Replace placeholder barrel with public API re-exports. Add 15 smoke tests covering Tool construction, invoke dispatch, error envelopes, and output helpers.
feaac99 to
3459e10
Compare
|
@greptile |
4d80253
into
feat/1-implement-code-first-agentstool-package
Summary
Extracts the Tool base class and 7 supporting modules from
kael.factory/lib/tool/into this standalone package'ssrc/, establishing the core of thecode-first-agents-toollibrary.types,args,json-schema,output-helpers,introspection,envelopes,tool-classsrc/utils.tswith only the 3 symbols needed (ToolOutput,jsonOutput,stringifyError)../utils.tsimports to./utils.tsinenvelopes.tsandtool-class.tssrc/index.tswith barrel re-exports of the full public APIzod@^4.0.0as production dependencypackage.jsonwith correct name, exports, and main fieldstsconfig.jsonwithallowImportingTsExtensionsandnoEmitCloses #3
Plan level: lean (8/13) | Depth: medium
Files changed
Verification
bunx tsc --noEmit— zero errorsbun test— 15/15 passbunx biome check— cleangrep -r '../lib/' src/— zero matches (no kael.factory paths)