agent-readable-ts 0.1.4 → 0.1.6
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 +30 -527
- package/dist/src/cli.js +31 -14
- package/dist/src/cli.js.map +1 -1
- package/dist/src/model.d.ts +2 -0
- package/dist/src/model.d.ts.map +1 -1
- package/dist/src/model.js +2 -1
- package/dist/src/model.js.map +1 -1
- package/dist/src/packages.d.ts +11 -0
- package/dist/src/packages.d.ts.map +1 -1
- package/dist/src/packages.js +157 -30
- package/dist/src/packages.js.map +1 -1
- package/dist/src/source-types.d.ts +5 -0
- package/dist/src/source-types.d.ts.map +1 -1
- package/dist/src/source-types.js +8 -0
- package/dist/src/source-types.js.map +1 -1
- package/docs/authoring.md +112 -0
- package/docs/examples.md +166 -0
- package/docs/faq.md +73 -0
- package/docs/getting-started.md +132 -0
- package/docs/why.md +43 -0
- package/package.json +10 -2
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Authoring Notes
|
|
2
|
+
|
|
3
|
+
Start with clear public method names and JSDoc. Add `agentNotes()` only when a
|
|
4
|
+
class or object has cross-method rules that are easy to miss.
|
|
5
|
+
|
|
6
|
+
Use `agentHelp()` rarely, when the auto-generated output is not the right shape
|
|
7
|
+
and you want to provide the full Markdown response yourself.
|
|
8
|
+
|
|
9
|
+
## `agentNotes()`
|
|
10
|
+
|
|
11
|
+
Define `agentNotes()` to append usage guidance after the generated public API
|
|
12
|
+
docs.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { AgentNoter } from "agent-readable-ts";
|
|
16
|
+
|
|
17
|
+
interface Connection {}
|
|
18
|
+
|
|
19
|
+
class DatabasePool implements AgentNoter {
|
|
20
|
+
acquire(): Promise<Connection> {
|
|
21
|
+
throw new Error("not implemented");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
release(conn: Connection): void {}
|
|
25
|
+
|
|
26
|
+
shutdown(): Promise<void> {
|
|
27
|
+
return Promise.resolve();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
agentNotes(): string {
|
|
31
|
+
return `
|
|
32
|
+
## Do
|
|
33
|
+
|
|
34
|
+
- Always call \`release(conn)\` after every \`acquire()\`, even on error.
|
|
35
|
+
- Call \`shutdown()\` during graceful application teardown.
|
|
36
|
+
|
|
37
|
+
## Do not
|
|
38
|
+
|
|
39
|
+
- Do not call \`acquire()\` after \`shutdown()\`.
|
|
40
|
+
- Do not share a \`Connection\` object across async tasks.
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`agentNotes()` is a good fit for:
|
|
47
|
+
|
|
48
|
+
- lifecycle and call ordering rules;
|
|
49
|
+
- preconditions and cleanup requirements;
|
|
50
|
+
- sync vs async constraints;
|
|
51
|
+
- streaming vs non-streaming behavior;
|
|
52
|
+
- important do and do-not guidance.
|
|
53
|
+
|
|
54
|
+
Avoid duplicating obvious method-level information that belongs in names,
|
|
55
|
+
signatures, or JSDoc.
|
|
56
|
+
|
|
57
|
+
## Inheritance
|
|
58
|
+
|
|
59
|
+
Notes accumulate across the inheritance chain in parent-to-child order.
|
|
60
|
+
|
|
61
|
+
Unlike Python, TypeScript does not automatically merge notes from separate
|
|
62
|
+
prototype methods. Implement `agentNotes()` on each class that has its own
|
|
63
|
+
cross-method rules.
|
|
64
|
+
|
|
65
|
+
## `agentHelp()`
|
|
66
|
+
|
|
67
|
+
Implement `agentHelp()` for full control over the returned Markdown:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { AgentHelper } from "agent-readable-ts";
|
|
71
|
+
|
|
72
|
+
class RateLimiter implements AgentHelper {
|
|
73
|
+
agentHelp(): string {
|
|
74
|
+
return `# RateLimiter
|
|
75
|
+
|
|
76
|
+
## Usage
|
|
77
|
+
|
|
78
|
+
- Create with \`new RateLimiter(maxRequests)\`.
|
|
79
|
+
- Call \`acquire()\` before making a request.
|
|
80
|
+
- Call \`release()\` after the request completes.
|
|
81
|
+
`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
If both `agentHelp()` and `agentNotes()` are defined on the same target,
|
|
87
|
+
`agentHelp()` wins and `agentNotes()` is ignored. The library emits a warning,
|
|
88
|
+
but authors should treat this as an API design error.
|
|
89
|
+
|
|
90
|
+
## Warning Output
|
|
91
|
+
|
|
92
|
+
By default, advisory warnings are written to `process.stderr`. You can redirect
|
|
93
|
+
or silence them:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { getWarnOutput, setWarnOutput } from "agent-readable-ts";
|
|
97
|
+
|
|
98
|
+
setWarnOutput((chunk: string) => {
|
|
99
|
+
console.log("[WARN]", chunk.trim());
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
setWarnOutput({
|
|
103
|
+
write(chunk: string) {
|
|
104
|
+
console.log(chunk);
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
setWarnOutput(null);
|
|
109
|
+
setWarnOutput(process.stderr);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`getWarnOutput()` returns the current warning sink.
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
## Installed Package
|
|
4
|
+
|
|
5
|
+
List all exports from an installed package:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install commander
|
|
9
|
+
npx agent-readable-ts commander
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Example output:
|
|
13
|
+
|
|
14
|
+
```markdown
|
|
15
|
+
# commander
|
|
16
|
+
|
|
17
|
+
## Exports
|
|
18
|
+
|
|
19
|
+
- `CommanderError` class
|
|
20
|
+
- `InvalidArgumentError` class
|
|
21
|
+
- `Argument` class
|
|
22
|
+
- `Option` class
|
|
23
|
+
- `Help` class
|
|
24
|
+
- `Command` class
|
|
25
|
+
- `createCommand(name: string): Command` function
|
|
26
|
+
- `createOption(flags: string, description: string): Option` function
|
|
27
|
+
- `createArgument(name: string, description: string): Argument` function
|
|
28
|
+
- `program` object
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Document a specific export:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
npx agent-readable-ts commander:Command
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Local File
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
npx agent-readable-ts ./src/widget.ts:Widget
|
|
41
|
+
npx agent-readable-ts ./src/util.ts:connect
|
|
42
|
+
npx agent-readable-ts ./dist/api.js:fetch
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
For `.js`, `.mjs`, and `.cjs` files, the CLI can read adjacent `.d.ts`,
|
|
46
|
+
`.d.mts`, and `.d.cts` declaration files when they exist.
|
|
47
|
+
|
|
48
|
+
## Wrapping a Class You Do Not Own
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { agentHelp } from "agent-readable-ts";
|
|
52
|
+
|
|
53
|
+
class Client {
|
|
54
|
+
connect(url: string): void {}
|
|
55
|
+
query(sql: string): unknown {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
class DocumentedClient extends Client {
|
|
61
|
+
agentNotes(): string {
|
|
62
|
+
return `
|
|
63
|
+
## Do
|
|
64
|
+
|
|
65
|
+
- Call \`connect()\` before \`query()\`.
|
|
66
|
+
|
|
67
|
+
## Do not
|
|
68
|
+
|
|
69
|
+
- Do not pass untrusted SQL directly to \`query()\`.
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
console.log(agentHelp(new DocumentedClient()));
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Inheritance With Accumulated Notes
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { agentHelp } from "agent-readable-ts";
|
|
81
|
+
|
|
82
|
+
class Sensor {
|
|
83
|
+
calibrate(offset: number): void {}
|
|
84
|
+
read(): number {
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
agentNotes(): string {
|
|
89
|
+
return `
|
|
90
|
+
## Do
|
|
91
|
+
|
|
92
|
+
- Call \`calibrate()\` once during setup, before \`read()\`.
|
|
93
|
+
|
|
94
|
+
## Do not
|
|
95
|
+
|
|
96
|
+
- Do not call \`read()\` before \`calibrate()\` on first use.
|
|
97
|
+
`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
class CalibratedSensor extends Sensor {
|
|
102
|
+
reset(): void {}
|
|
103
|
+
|
|
104
|
+
override agentNotes(): string {
|
|
105
|
+
return `
|
|
106
|
+
## Do
|
|
107
|
+
|
|
108
|
+
- Use \`reset()\` only when recalibration is required.
|
|
109
|
+
|
|
110
|
+
## Do not
|
|
111
|
+
|
|
112
|
+
- Do not call \`reset()\` in the hot read path.
|
|
113
|
+
`;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log(agentHelp(new CalibratedSensor()));
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Notes are emitted in parent-to-child order. If rules conflict, the child class
|
|
121
|
+
guidance should be treated as more specific.
|
|
122
|
+
|
|
123
|
+
## Full Control With `agentHelp()`
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { agentHelp } from "agent-readable-ts";
|
|
127
|
+
|
|
128
|
+
class RateLimiter {
|
|
129
|
+
agentHelp(): string {
|
|
130
|
+
return `# RateLimiter
|
|
131
|
+
|
|
132
|
+
## Usage
|
|
133
|
+
|
|
134
|
+
- Create with \`new RateLimiter(maxRequests)\`.
|
|
135
|
+
- Call \`acquire()\` before making a request.
|
|
136
|
+
- Call \`release()\` after the request completes.
|
|
137
|
+
`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
console.log(agentHelp(new RateLimiter()));
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
When `agentHelp()` exists, its returned Markdown is used verbatim.
|
|
145
|
+
|
|
146
|
+
## Functions and Bound Methods
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { agentHelp } from "agent-readable-ts";
|
|
150
|
+
|
|
151
|
+
function connect(host: string, port: number): void {}
|
|
152
|
+
|
|
153
|
+
class Runner {
|
|
154
|
+
execute(command: string): number {
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const runner = new Runner();
|
|
160
|
+
|
|
161
|
+
console.log(agentHelp(connect));
|
|
162
|
+
console.log(agentHelp(runner.execute.bind(runner)));
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Bound methods may lose original parameter names at runtime and fall back to
|
|
166
|
+
`arg0`, `arg1`, and so on.
|
package/docs/faq.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# FAQ
|
|
2
|
+
|
|
3
|
+
## Which Node versions are supported?
|
|
4
|
+
|
|
5
|
+
Node 20.6 or newer. The CLI's package resolution uses the synchronous
|
|
6
|
+
`import.meta.resolve()`, which is available from Node 20.6.
|
|
7
|
+
|
|
8
|
+
## Should I use the library API or the CLI?
|
|
9
|
+
|
|
10
|
+
Use `agentHelp(target)` when the target is already loaded in your program.
|
|
11
|
+
|
|
12
|
+
Use the CLI when you want better TypeScript signatures from source files or
|
|
13
|
+
declaration files:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npx agent-readable-ts ./src/widget.ts:Widget
|
|
17
|
+
npx agent-readable-ts commander:Command
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Can runtime reflection recover TypeScript types?
|
|
21
|
+
|
|
22
|
+
No. TypeScript types, interfaces, overloads, generic parameters, return types,
|
|
23
|
+
and doc comments are erased from compiled JavaScript.
|
|
24
|
+
|
|
25
|
+
The CLI can recover more type information by parsing `.ts` files or adjacent
|
|
26
|
+
declaration files.
|
|
27
|
+
|
|
28
|
+
## Why do some parameters show up as `arg0`?
|
|
29
|
+
|
|
30
|
+
Parameter names come from `Function.prototype.toString()` when possible. Native
|
|
31
|
+
functions, bound functions, destructured parameters, and some compiled output do
|
|
32
|
+
not preserve useful names, so the library falls back to `arg0`, `arg1`, and so
|
|
33
|
+
on.
|
|
34
|
+
|
|
35
|
+
## Are constructors or getters invoked?
|
|
36
|
+
|
|
37
|
+
No. Constructors are not called during introspection, and getters are not
|
|
38
|
+
invoked.
|
|
39
|
+
|
|
40
|
+
## Are private members shown?
|
|
41
|
+
|
|
42
|
+
JavaScript `#private` fields and methods are not reflectable and never appear.
|
|
43
|
+
|
|
44
|
+
TypeScript `private` and `protected` are compile-time constructs. The library
|
|
45
|
+
excludes names starting with `_`, but runtime JavaScript cannot perfectly detect
|
|
46
|
+
TypeScript visibility.
|
|
47
|
+
|
|
48
|
+
## Why is `typescript` a dependency?
|
|
49
|
+
|
|
50
|
+
The CLI uses the TypeScript compiler API to recover type signatures from `.ts`
|
|
51
|
+
sources and declaration files. Bundling it keeps one-off runs such as
|
|
52
|
+
`npx agent-readable-ts commander:Command` fully typed out of the box, at the
|
|
53
|
+
cost of a larger install. The runtime reflection in `agentHelp()` itself does
|
|
54
|
+
not need the compiler — if the compiler cannot be loaded, the library degrades
|
|
55
|
+
to runtime-only signatures instead of failing.
|
|
56
|
+
|
|
57
|
+
## Does the CLI fetch packages automatically?
|
|
58
|
+
|
|
59
|
+
No. Missing packages are only fetched when you pass `--install`.
|
|
60
|
+
|
|
61
|
+
Fetched packages go into an isolated cache and are installed with
|
|
62
|
+
`--ignore-scripts`. See [Getting Started](getting-started.md#on-demand-package-fetching).
|
|
63
|
+
|
|
64
|
+
`--ignore-scripts` blocks package install scripts, but inspecting a package
|
|
65
|
+
still executes its top-level code when it is imported — see
|
|
66
|
+
[Security](getting-started.md#security).
|
|
67
|
+
|
|
68
|
+
## Is this the same as the Python package?
|
|
69
|
+
|
|
70
|
+
It is the TypeScript and JavaScript sibling of
|
|
71
|
+
[agent-readable](https://github.com/zydo/agent-readable). The shared idea is the
|
|
72
|
+
same: inspect the current API surface and author-provided usage rules before
|
|
73
|
+
coding against an unfamiliar target.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
`agent-readable-ts` can be used as a library from TypeScript or JavaScript, and
|
|
4
|
+
as a CLI for inspecting local files or npm packages.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install agent-readable-ts
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Node 20.6 or newer is required.
|
|
13
|
+
|
|
14
|
+
## Library Usage
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { agentHelp } from "agent-readable-ts";
|
|
18
|
+
|
|
19
|
+
console.log(agentHelp(SomeClass)); // class constructor
|
|
20
|
+
console.log(agentHelp(new SomeClass())); // class instance
|
|
21
|
+
console.log(agentHelp(someFunction)); // function or arrow function
|
|
22
|
+
console.log(agentHelp({ a: 1 })); // plain object
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The programmatic API uses runtime JavaScript reflection. It can show public
|
|
26
|
+
members, parameter names when available, and `agentNotes()`/`agentHelp()` output,
|
|
27
|
+
but it cannot recover TypeScript-only types from compiled JavaScript.
|
|
28
|
+
|
|
29
|
+
## CLI Usage
|
|
30
|
+
|
|
31
|
+
The CLI can inspect installed npm packages, Node builtins, local JavaScript
|
|
32
|
+
files, and local TypeScript files.
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
npx agent-readable-ts commander
|
|
36
|
+
npx agent-readable-ts commander:Command
|
|
37
|
+
npx agent-readable-ts node:fs:ReadStream
|
|
38
|
+
npx agent-readable-ts ./src/widget.ts:Widget
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`commander` is only an example target. Use any trusted installed package, local
|
|
42
|
+
module, or local TypeScript file.
|
|
43
|
+
|
|
44
|
+
Usage:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
agent-readable-ts [--install] <package-name>[:<export-name>]
|
|
48
|
+
agent-readable-ts <module-path>[:<export-name>]
|
|
49
|
+
agent-readable-ts node:<builtin>[:<export-name>]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
- `package-name`: an installed npm package, such as `commander`, `pino`, or
|
|
53
|
+
`@scope/package`.
|
|
54
|
+
- `builtin`: a Node builtin module, such as `node:fs` or `node:util`. Type
|
|
55
|
+
signatures come from `@types/node` when it is installed.
|
|
56
|
+
- `module-path`: a `.js`, `.mjs`, `.cjs`, or `.ts` file path relative to the
|
|
57
|
+
current directory.
|
|
58
|
+
- `export-name`: the named export to document. Use dots for nested access, such
|
|
59
|
+
as `Things.Helper`.
|
|
60
|
+
- `--install`: allow the CLI to fetch a package on demand when it is not
|
|
61
|
+
installed locally.
|
|
62
|
+
|
|
63
|
+
If no export name is given for a package, all exports are listed. If no export
|
|
64
|
+
name is given for a file, the module namespace object is documented.
|
|
65
|
+
|
|
66
|
+
`.ts` files load through Node's built-in type stripping (enabled by default on
|
|
67
|
+
Node 22.18+). On older runtimes, register a TypeScript loader such as tsx first
|
|
68
|
+
(installed in the project — a global tsx is not visible to `--import`), for
|
|
69
|
+
example `NODE_OPTIONS="--import tsx" npx agent-readable-ts ./src/widget.ts:Widget`.
|
|
70
|
+
|
|
71
|
+
## One-Off CLI Use
|
|
72
|
+
|
|
73
|
+
Two tool options (`npx` and `pnpm`) — pick whichever matches your package manager. Each one-off command runs the CLI without adding a dependency to the current project, and the downloaded package is cached, so repeat runs start instantly. Replace `commander` with any installed package, Node builtin, or local file target.
|
|
74
|
+
|
|
75
|
+
### npm
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
# One-off — npx fetches and caches the CLI
|
|
79
|
+
npx agent-readable-ts commander
|
|
80
|
+
|
|
81
|
+
# Repeated use — install once globally, then run the bare command
|
|
82
|
+
npm install -g agent-readable-ts
|
|
83
|
+
agent-readable-ts commander
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### pnpm
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
# One-off — pnpm's equivalent of npx
|
|
90
|
+
pnpm dlx agent-readable-ts commander
|
|
91
|
+
|
|
92
|
+
# Repeated use — install once globally, then run the bare command
|
|
93
|
+
pnpm add -g agent-readable-ts
|
|
94
|
+
agent-readable-ts commander
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`yarn dlx` and `bunx` work the same way.
|
|
98
|
+
|
|
99
|
+
## Your Own Project
|
|
100
|
+
|
|
101
|
+
One-off runs resolve packages from the current project's `node_modules` first and load local files by path, so your own code needs no install:
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
npx agent-readable-ts ./src/widget.ts:Widget
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`.ts` files load through Node's built-in type stripping (enabled by default on Node 22.18+); on older runtimes register a loader such as tsx first — see [CLI Usage](#cli-usage).
|
|
108
|
+
|
|
109
|
+
## On-Demand Package Fetching
|
|
110
|
+
|
|
111
|
+
Packages are resolved in order: from the current project's `node_modules`, then
|
|
112
|
+
from the CLI's own install, then from the cache. This means one-off runs such as
|
|
113
|
+
`npx agent-readable-ts <package>` see the packages your project already has
|
|
114
|
+
installed. For anything not found, the CLI refuses to fetch unless `--install`
|
|
115
|
+
is passed:
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
npx agent-readable-ts --install left-pad
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Fetched packages go into `~/.cache/agent-readable-ts`, or the directory named by
|
|
122
|
+
`AGENT_READABLE_CACHE`. They are never installed into the current project.
|
|
123
|
+
|
|
124
|
+
The install uses `npm install --ignore-scripts`, so package lifecycle scripts are
|
|
125
|
+
not run. Concurrent installs into the shared cache are serialized with a lock.
|
|
126
|
+
Cached packages load offline without requiring `--install` again.
|
|
127
|
+
|
|
128
|
+
## Security
|
|
129
|
+
|
|
130
|
+
The CLI imports packages and local modules in order to inspect them. Importing a
|
|
131
|
+
module executes its top-level code. Only inspect packages and files you trust to
|
|
132
|
+
run on your machine.
|
package/docs/why.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Why agent-readable-ts?
|
|
2
|
+
|
|
3
|
+
Coding agents often guess a library API from stale memory: inventing methods,
|
|
4
|
+
using old signatures, or missing lifecycle rules that are not visible from a
|
|
5
|
+
method list alone.
|
|
6
|
+
|
|
7
|
+
`agent-readable-ts` gives agents a small, live, API-shaped context before they
|
|
8
|
+
write code:
|
|
9
|
+
|
|
10
|
+
- the public callable surface that can be discovered safely;
|
|
11
|
+
- TypeScript signatures when the CLI can parse source or declaration files;
|
|
12
|
+
- author-supplied usage rules from `agentNotes()`;
|
|
13
|
+
- full custom guidance from `agentHelp()` when a library needs it.
|
|
14
|
+
|
|
15
|
+
This reduces failed edit-test-retry loops and keeps the agent focused on the API
|
|
16
|
+
that exists in the current project.
|
|
17
|
+
|
|
18
|
+
## Why Not Just README Docs?
|
|
19
|
+
|
|
20
|
+
README files are written for people and often cover happy-path examples. Coding
|
|
21
|
+
agents need a compact answer to narrower questions:
|
|
22
|
+
|
|
23
|
+
- What members exist on this object right now?
|
|
24
|
+
- Which methods are public?
|
|
25
|
+
- What is the current call shape?
|
|
26
|
+
- Are there ordering, cleanup, async, or safety rules?
|
|
27
|
+
|
|
28
|
+
`agent-readable-ts` puts that information next to the implementation and exposes
|
|
29
|
+
it through one consistent inspection path.
|
|
30
|
+
|
|
31
|
+
## Runtime and Source Inspection
|
|
32
|
+
|
|
33
|
+
TypeScript type annotations do not exist at runtime. The library API therefore
|
|
34
|
+
uses conservative JavaScript reflection. The CLI fills more gaps by parsing
|
|
35
|
+
`.ts` source or adjacent `.d.ts` declaration files for packages and JavaScript
|
|
36
|
+
modules.
|
|
37
|
+
|
|
38
|
+
When type detail matters, prefer the CLI:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
npx agent-readable-ts ./src/widget.ts:Widget
|
|
42
|
+
npx agent-readable-ts commander:Command
|
|
43
|
+
```
|
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-readable-ts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Attach agent-oriented documentation to any class, object, or function",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/src/index.d.ts",
|
|
10
|
+
"default": "./dist/src/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
7
14
|
"type": "module",
|
|
8
15
|
"repository": {
|
|
9
16
|
"type": "git",
|
|
@@ -17,6 +24,7 @@
|
|
|
17
24
|
"agent-readable-ts": "dist/src/cli.js"
|
|
18
25
|
},
|
|
19
26
|
"files": [
|
|
27
|
+
"docs",
|
|
20
28
|
"dist/src"
|
|
21
29
|
],
|
|
22
30
|
"scripts": {
|
|
@@ -35,7 +43,7 @@
|
|
|
35
43
|
],
|
|
36
44
|
"license": "MIT",
|
|
37
45
|
"engines": {
|
|
38
|
-
"node": ">=20.
|
|
46
|
+
"node": ">=20.6.0"
|
|
39
47
|
},
|
|
40
48
|
"dependencies": {
|
|
41
49
|
"typescript": "^5.5.0"
|