@alint-js/agent 0.0.4

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 ADDED
@@ -0,0 +1,59 @@
1
+ # `@alint-js/agent`
2
+
3
+ > [!IMPORTANT]
4
+ > This package is a WIP. APIs may be subject to major changes.
5
+
6
+ **BYOA** — **B**ring **Y**our **O**wn **A**gent.
7
+
8
+ The agent-agnostic contract for tool-using alint rules. Optional layer on top of
9
+ `@alint-js/core`. Install only when a rule needs an agent.
10
+
11
+ ## What it does
12
+
13
+ Defines the small contract that lets a rule run a multi-step tool loop without
14
+ building an LLM SDK, while staying free to swap the underlying agent framework:
15
+
16
+ ## Concepts
17
+
18
+ ### AgentAdapter
19
+
20
+ `(request) => Promise<{ answer, usage }>`. A rule hands a request (instructions, prompt, model, tools) to an adapter; the adapter runs the loop.
21
+
22
+ ### AgentTool
23
+
24
+ A framework-free tool shape (`name`, `description`, JSON Schema `parameters`, `execute`). Each adapter translates it to its framework's tool format.
25
+
26
+ ### defineTool
27
+
28
+ Identity helper for authoring tools with a checked shape.
29
+
30
+ ## How to use
31
+
32
+ Write tools with `defineTool`, then pass them plus an adapter to your rule:
33
+
34
+ ```ts
35
+ import type { AgentAdapter } from '@alint-js/agent'
36
+
37
+ import { defineTool } from '@alint-js/agent'
38
+
39
+ const grep = defineTool({
40
+ description: 'Search the repo.',
41
+ execute: async input => /* ... */ '',
42
+ name: 'grep',
43
+ parameters: { properties: { query: { type: 'string' } }, required: ['query'], type: 'object' },
44
+ })
45
+
46
+ async function run(adapter: AgentAdapter) {
47
+ return adapter({ instructions: '...', model, prompt: '...', tools: [grep] })
48
+ }
49
+ ```
50
+
51
+ The adapter itself comes from a framework package (e.g. an adapter for Apeira agent or Pi agent) or your own function of type `AgentAdapter`.
52
+
53
+ ## When to use
54
+
55
+ - You run rules that need to explore (read files, search, call tools) across multiple steps before reporting, not single one-shot "judge" rules.
56
+
57
+ ## When not to use
58
+
59
+ - You run one-shot, no-tool "judge" rules. They don't need an agent. Keep them on the plain `@alint-js/core` rule DSL. If you don't write tool-using rules, you may not need this.
@@ -0,0 +1,30 @@
1
+ import { ResolvedModel } from "@alint-js/core";
2
+
3
+ //#region src/index.d.ts
4
+ type AgentAdapter = (request: AgentRequest) => Promise<AgentResult>;
5
+ interface AgentRequest {
6
+ instructions: string;
7
+ model: ResolvedModel;
8
+ prompt: string;
9
+ signal?: AbortSignal;
10
+ tools: AgentTool[];
11
+ }
12
+ interface AgentResult {
13
+ answer: string;
14
+ usage?: AgentUsage;
15
+ }
16
+ /** Agent-agnostic tool definition. Each adapter translates it to its framework's tool format. */
17
+ interface AgentTool {
18
+ description: string;
19
+ execute: (input: unknown) => Promise<unknown> | unknown;
20
+ name: string;
21
+ parameters: Record<string, unknown>;
22
+ }
23
+ interface AgentUsage {
24
+ inputTokens?: number;
25
+ outputTokens?: number;
26
+ totalTokens?: number;
27
+ }
28
+ declare function defineTool(tool: AgentTool): AgentTool;
29
+ //#endregion
30
+ export { AgentAdapter, AgentRequest, AgentResult, AgentTool, AgentUsage, defineTool };
package/dist/index.mjs ADDED
@@ -0,0 +1,6 @@
1
+ //#region src/index.ts
2
+ function defineTool(tool) {
3
+ return tool;
4
+ }
5
+ //#endregion
6
+ export { defineTool };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@alint-js/agent",
3
+ "type": "module",
4
+ "version": "0.0.4",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.mts",
8
+ "default": "./dist/index.mjs"
9
+ },
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "dependencies": {
16
+ "@alint-js/core": "0.0.4"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^26.0.1",
20
+ "tsdown": "^0.22.3",
21
+ "typescript": "^6.0.3",
22
+ "vitest": "^4.1.9"
23
+ },
24
+ "scripts": {
25
+ "build": "tsdown",
26
+ "typecheck": "tsc -p tsconfig.json --noEmit",
27
+ "test": "vitest run --config vitest.config.ts"
28
+ }
29
+ }