agent-readable-ts 0.1.4 → 0.1.5
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 +31 -527
- package/docs/authoring.md +112 -0
- package/docs/examples.md +166 -0
- package/docs/faq.md +59 -0
- package/docs/getting-started.md +94 -0
- package/docs/why.md +43 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,305 +1,23 @@
|
|
|
1
1
|
# agent-readable-ts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/zydo/agent-readable-ts/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/agent-readable-ts)
|
|
4
5
|
|
|
5
|
-
`agent-readable-ts`
|
|
6
|
+
`agent-readable-ts` helps coding agents inspect the live public surface of a
|
|
7
|
+
TypeScript or JavaScript API before they write code against it.
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
Library authors can add agent-oriented usage rules next to a class, object, or
|
|
10
|
+
function. Consumers call `agentHelp(target)` or the `agent-readable-ts` CLI to get
|
|
11
|
+
compact Markdown with the real callable surface plus any author-supplied
|
|
12
|
+
behavioral notes.
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## Other languages
|
|
15
|
-
|
|
16
|
-
- **Python:** [agent-readable](https://github.com/zydo/agent-readable) — same idea for Python packages and classes.
|
|
17
|
-
|
|
18
|
-
## Install
|
|
19
|
-
|
|
20
|
-
```sh
|
|
21
|
-
npm install agent-readable-ts
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## CLI
|
|
25
|
-
|
|
26
|
-
The package includes a CLI for generating documentation from the command line. It works with local files **and installed npm packages**.
|
|
27
|
-
|
|
28
|
-
```sh
|
|
29
|
-
npx agent-readable-ts commander # list all exports
|
|
30
|
-
npx agent-readable-ts commander:Command # document a specific export
|
|
31
|
-
npx agent-readable-ts ./src/widget.ts:Widget # a local TypeScript file
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Usage
|
|
35
|
-
|
|
36
|
-
```sh
|
|
37
|
-
agent-readable-ts [--install] <package-name>[:<export-name>]
|
|
38
|
-
agent-readable-ts <module-path>[:<export-name>]
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
- **`package-name`** — any installed npm package (e.g. `commander`, `pino`, `@scope/package`)
|
|
42
|
-
- **`module-path`** — a file path (`.js`, `.mjs`, or `.ts`) relative to the current directory
|
|
43
|
-
- **`export-name`** — the named export to document (use dots for nested access, e.g. `Things.Helper`)
|
|
44
|
-
- **`--install`** — allow fetching a package on demand when it is not installed locally (see [Security](#security))
|
|
45
|
-
|
|
46
|
-
If no export name is given for a **package**, all exports are listed. If no export name is given for a **file**, the module namespace object is documented.
|
|
47
|
-
|
|
48
|
-
> `.ts` files require `tsx` to be installed. It is included as a devDependency, and `npx` resolves it automatically.
|
|
49
|
-
|
|
50
|
-
### Examples
|
|
51
|
-
|
|
52
|
-
List all exports from an installed package:
|
|
53
|
-
|
|
54
|
-
```sh
|
|
55
|
-
npm install commander
|
|
56
|
-
npx agent-readable-ts commander
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Output:
|
|
60
|
-
|
|
61
|
-
```markdown
|
|
62
|
-
# commander
|
|
63
|
-
|
|
64
|
-
## Exports
|
|
65
|
-
|
|
66
|
-
- `CommanderError` class
|
|
67
|
-
- `InvalidArgumentError` class
|
|
68
|
-
- `Argument` class
|
|
69
|
-
- `Option` class
|
|
70
|
-
- `Help` class
|
|
71
|
-
- `Command` class
|
|
72
|
-
- `createCommand(name: string): Command` function
|
|
73
|
-
- `createOption(flags: string, description: string): Option` function
|
|
74
|
-
- `createArgument(name: string, description: string): Argument` function
|
|
75
|
-
- `program` object
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
Document a specific export with full type signatures:
|
|
14
|
+
To let your coding agent automatically call `agentHelp()` before using an
|
|
15
|
+
unfamiliar API, install the companion skill:
|
|
79
16
|
|
|
80
17
|
```sh
|
|
81
|
-
npx agent-readable
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Output:
|
|
85
|
-
|
|
86
|
-
```markdown
|
|
87
|
-
# Command
|
|
88
|
-
|
|
89
|
-
## Public API
|
|
90
|
-
|
|
91
|
-
- `action(fn: (this: this, ...args: any[]) => void | Promise<void>): this` method
|
|
92
|
-
- `addArgument(arg: Argument): this` method
|
|
93
|
-
- `addCommand(cmd: Command, opts: CommandOptions): this` method
|
|
94
|
-
- `addOption(option: Option): this` method
|
|
95
|
-
- `alias(): string` method
|
|
96
|
-
- `argument(name: string, description: string, defaultValue: unknown): this` method
|
|
97
|
-
- `command(nameAndArgs: string, description: string, opts: ExecutableCommandOptions): this` method
|
|
98
|
-
- `description(): string` method
|
|
99
|
-
- `error(message: string, errorOptions: ErrorOptions): never` method
|
|
100
|
-
- `hook(event: HookEvent, listener: (...args: any[]) => void | Promise<void>): this` method
|
|
101
|
-
- `option(flags: string, description: string, defaultValue: unknown): this` method
|
|
102
|
-
- `parse(argv: readonly string[], parseOptions: ParseOptions): this` method
|
|
103
|
-
- `parseAsync(argv: readonly string[], parseOptions: ParseOptions): Promise<this>` method
|
|
104
|
-
- `requiredOption(flags: string, description: string, defaultValue: unknown): this` method
|
|
105
|
-
- `version(str: string, flags: string, description: string): this` method
|
|
106
|
-
- ... (80+ methods total)
|
|
107
|
-
|
|
108
|
-
## Agent usage rules
|
|
109
|
-
|
|
110
|
-
- Prefer the public API listed above.
|
|
111
|
-
- Do not use private, protected, underscored, or internal members.
|
|
112
|
-
- Do not invent unsupported behavior.
|
|
113
|
-
- If usage is ambiguous, prefer the simplest documented usage pattern.
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Document a local file:
|
|
117
|
-
|
|
118
|
-
```sh
|
|
119
|
-
npx agent-readable-ts ./src/widget.ts:Widget # a class export
|
|
120
|
-
npx agent-readable-ts ./src/util.ts:connect # a function export
|
|
121
|
-
npx agent-readable-ts ./dist/api.js:fetch # a .js file with adjacent api.d.ts
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Security
|
|
125
|
-
|
|
126
|
-
To document a package, the CLI imports it, which executes the package's top-level code — only point it at packages you trust to run on your machine.
|
|
127
|
-
|
|
128
|
-
When a package is not resolvable from the current project, the CLI can fetch it on demand with `npm install`. This never happens silently:
|
|
129
|
-
|
|
130
|
-
- **Opt-in only.** On-demand fetching requires the `--install` flag. Without it, the CLI exits with an error telling you how to install the package yourself.
|
|
131
|
-
- **Isolated cache.** Fetched packages go into `~/.cache/agent-readable-ts` (override with the `AGENT_READABLE_CACHE` environment variable), never into your project's `node_modules` or `package.json`.
|
|
132
|
-
- **No lifecycle scripts.** The install runs with `--ignore-scripts`, so `preinstall`/`postinstall` scripts of fetched packages are never executed.
|
|
133
|
-
- **No re-fetching.** Packages already present in the cache are loaded from disk without touching the network, and never require `--install` again.
|
|
134
|
-
|
|
135
|
-
Packages already installed in your project are always loaded directly — no network access, no cache.
|
|
136
|
-
|
|
137
|
-
## Two protocols
|
|
138
|
-
|
|
139
|
-
| Protocol | Role | Output behavior |
|
|
140
|
-
| -------------- | ----------------- | ------------------------------------------------ |
|
|
141
|
-
| `agentHelp()` | Full replacement | Returned Markdown is used verbatim |
|
|
142
|
-
| `agentNotes()` | Additive guidance | Notes are appended after auto-generated API docs |
|
|
143
|
-
|
|
144
|
-
### `agentHelp()` — Full replacement
|
|
145
|
-
|
|
146
|
-
If a target implements `agentHelp()`, the returned string **is** the output verbatim. No auto-generated sections are added.
|
|
147
|
-
|
|
148
|
-
```ts
|
|
149
|
-
import { AgentHelper, agentHelp } from "agent-readable-ts";
|
|
150
|
-
|
|
151
|
-
class RateLimiter implements AgentHelper {
|
|
152
|
-
agentHelp(): string {
|
|
153
|
-
return `# RateLimiter
|
|
154
|
-
|
|
155
|
-
## Usage
|
|
156
|
-
|
|
157
|
-
- Create with \`new RateLimiter(maxRequests)\`.
|
|
158
|
-
- Call \`acquire()\` before making a request.
|
|
159
|
-
- Call \`release()\` after the request completes.
|
|
160
|
-
|
|
161
|
-
## Limits
|
|
162
|
-
|
|
163
|
-
- Default max is 100 concurrent requests.
|
|
164
|
-
- Exceeding the limit blocks until a slot opens.
|
|
165
|
-
`;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
console.log(agentHelp(new RateLimiter()));
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
Output:
|
|
173
|
-
|
|
174
|
-
```markdown
|
|
175
|
-
# RateLimiter
|
|
176
|
-
|
|
177
|
-
## Usage
|
|
178
|
-
|
|
179
|
-
- Create with `new RateLimiter(maxRequests)`.
|
|
180
|
-
- Call `acquire()` before making a request.
|
|
181
|
-
- Call `release()` after the request completes.
|
|
182
|
-
|
|
183
|
-
## Limits
|
|
184
|
-
|
|
185
|
-
- Default max is 100 concurrent requests.
|
|
186
|
-
- Exceeding the limit blocks until a slot opens.
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
If the target also defines `agentNotes()`, a warning is written to stderr and the notes are dropped.
|
|
190
|
-
|
|
191
|
-
### `agentNotes()` — Additive guidance
|
|
192
|
-
|
|
193
|
-
Define `agentNotes()` on any class to append usage rules to the auto-generated documentation. Notes accumulate across the inheritance chain in parent-to-child order.
|
|
194
|
-
|
|
195
|
-
```ts
|
|
196
|
-
import { AgentNoter, agentHelp } from "agent-readable-ts";
|
|
197
|
-
|
|
198
|
-
class Sensor {
|
|
199
|
-
calibrate(offset: number): void {}
|
|
200
|
-
read(): number {
|
|
201
|
-
return 0;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
agentNotes(): string {
|
|
205
|
-
return `
|
|
206
|
-
## Do
|
|
207
|
-
|
|
208
|
-
- Call \`calibrate()\` once during setup, before \`read()\`.
|
|
209
|
-
|
|
210
|
-
## Do not
|
|
211
|
-
|
|
212
|
-
- Do not call \`read()\` before \`calibrate()\` on first use.
|
|
213
|
-
`;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
console.log(agentHelp(new Sensor()));
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
### `agentHelp(target)` entry point
|
|
221
|
-
|
|
222
|
-
The single entry point accepts:
|
|
223
|
-
|
|
224
|
-
- Class constructors
|
|
225
|
-
- Class instances
|
|
226
|
-
- Plain objects
|
|
227
|
-
- Plain functions
|
|
228
|
-
- Arrow functions
|
|
229
|
-
- Bound method values
|
|
230
|
-
- Callable objects
|
|
231
|
-
|
|
232
|
-
```ts
|
|
233
|
-
import { agentHelp } from "agent-readable-ts";
|
|
234
|
-
|
|
235
|
-
agentHelp(MyClass); // class constructor
|
|
236
|
-
agentHelp(new MyClass()); // class instance
|
|
237
|
-
agentHelp({ a: 1 }); // plain object
|
|
238
|
-
agentHelp(myFunction); // function
|
|
239
|
-
agentHelp(obj.method.bind(obj)); // bound method
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
## Examples
|
|
243
|
-
|
|
244
|
-
### Example 1: Wrapping a class you do not own
|
|
245
|
-
|
|
246
|
-
```ts
|
|
247
|
-
import { agentHelp } from "agent-readable-ts";
|
|
248
|
-
|
|
249
|
-
class Client {
|
|
250
|
-
connect(url: string): void {}
|
|
251
|
-
query(sql: string): unknown {
|
|
252
|
-
return undefined;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
class DocumentedClient extends Client {
|
|
257
|
-
agentNotes(): string {
|
|
258
|
-
return `
|
|
259
|
-
## Do
|
|
260
|
-
|
|
261
|
-
- Call \`connect()\` before \`query()\`.
|
|
262
|
-
|
|
263
|
-
## Do not
|
|
264
|
-
|
|
265
|
-
- Do not pass untrusted SQL directly to \`query()\`.
|
|
266
|
-
`;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
console.log(agentHelp(new DocumentedClient()));
|
|
18
|
+
npx skills add zydo/skills --skill agent-readable
|
|
271
19
|
```
|
|
272
20
|
|
|
273
|
-
Output:
|
|
274
|
-
|
|
275
|
-
```markdown
|
|
276
|
-
# DocumentedClient
|
|
277
|
-
|
|
278
|
-
## Public API
|
|
279
|
-
|
|
280
|
-
- `connect(url)` method
|
|
281
|
-
- `query(sql)` method
|
|
282
|
-
|
|
283
|
-
## Agent usage rules
|
|
284
|
-
|
|
285
|
-
- Prefer the public API listed above.
|
|
286
|
-
- Do not use private, protected, underscored, or internal members.
|
|
287
|
-
- Do not invent unsupported behavior.
|
|
288
|
-
- If usage is ambiguous, prefer the simplest documented usage pattern.
|
|
289
|
-
|
|
290
|
-
## Notes from DocumentedClient
|
|
291
|
-
|
|
292
|
-
## Do
|
|
293
|
-
|
|
294
|
-
- Call `connect()` before `query()`.
|
|
295
|
-
|
|
296
|
-
## Do not
|
|
297
|
-
|
|
298
|
-
- Do not pass untrusted SQL directly to `query()`.
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
### Example 2: Inheritance with accumulated notes
|
|
302
|
-
|
|
303
21
|
```ts
|
|
304
22
|
import { agentHelp } from "agent-readable-ts";
|
|
305
23
|
|
|
@@ -310,255 +28,41 @@ class Sensor {
|
|
|
310
28
|
}
|
|
311
29
|
|
|
312
30
|
agentNotes(): string {
|
|
313
|
-
return `
|
|
314
|
-
## Do
|
|
315
|
-
|
|
316
|
-
- Call \`calibrate()\` once during setup, before \`read()\`.
|
|
317
|
-
|
|
318
|
-
## Do not
|
|
319
|
-
|
|
320
|
-
- Do not call \`read()\` before \`calibrate()\` on first use.
|
|
321
|
-
`;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
class CalibratedSensor extends Sensor {
|
|
326
|
-
reset(): void {}
|
|
327
|
-
|
|
328
|
-
override agentNotes(): string {
|
|
329
|
-
return `
|
|
330
|
-
## Do
|
|
331
|
-
|
|
332
|
-
- Use \`reset()\` only when recalibration is required.
|
|
333
|
-
|
|
334
|
-
## Do not
|
|
335
|
-
|
|
336
|
-
- Do not call \`reset()\` in the hot read path.
|
|
337
|
-
`;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
console.log(agentHelp(new CalibratedSensor()));
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
Output:
|
|
345
|
-
|
|
346
|
-
```markdown
|
|
347
|
-
# CalibratedSensor
|
|
348
|
-
|
|
349
|
-
## Public API
|
|
350
|
-
|
|
351
|
-
- `calibrate(offset)` method
|
|
352
|
-
- `read()` method
|
|
353
|
-
- `reset()` method
|
|
354
|
-
|
|
355
|
-
## Agent usage rules
|
|
356
|
-
|
|
357
|
-
- Prefer the public API listed above.
|
|
358
|
-
- Do not use private, protected, underscored, or internal members.
|
|
359
|
-
- Do not invent unsupported behavior.
|
|
360
|
-
- If usage is ambiguous, prefer the simplest documented usage pattern.
|
|
361
|
-
|
|
362
|
-
## Notes from Sensor
|
|
363
|
-
|
|
364
|
-
## Do
|
|
365
|
-
|
|
366
|
-
- Call `calibrate()` once during setup, before `read()`.
|
|
367
|
-
|
|
368
|
-
## Do not
|
|
369
|
-
|
|
370
|
-
- Do not call `read()` before `calibrate()` on first use.
|
|
371
|
-
|
|
372
|
-
## Notes from CalibratedSensor (extends Sensor; if notes conflict, these take precedence)
|
|
373
|
-
|
|
374
|
-
## Do
|
|
375
|
-
|
|
376
|
-
- Use `reset()` only when recalibration is required.
|
|
377
|
-
|
|
378
|
-
## Do not
|
|
379
|
-
|
|
380
|
-
- Do not call `reset()` in the hot read path.
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
### Example 3: Full control via `agentHelp()`
|
|
384
|
-
|
|
385
|
-
```ts
|
|
386
|
-
import { agentHelp } from "agent-readable-ts";
|
|
387
|
-
|
|
388
|
-
class RateLimiter {
|
|
389
|
-
agentHelp(): string {
|
|
390
|
-
return `# RateLimiter
|
|
391
|
-
|
|
392
|
-
## Usage
|
|
393
|
-
|
|
394
|
-
- Create with \`new RateLimiter(maxRequests)\`.
|
|
395
|
-
- Call \`acquire()\` before making a request.
|
|
396
|
-
- Call \`release()\` after the request completes.
|
|
397
|
-
|
|
398
|
-
## Limits
|
|
399
|
-
|
|
400
|
-
- Default max is 100 concurrent requests.
|
|
401
|
-
- Exceeding the limit blocks until a slot opens.
|
|
402
|
-
`;
|
|
403
|
-
}
|
|
404
|
-
agentNotes(): string {
|
|
405
|
-
return "This is ignored because agentHelp() owns the full output.";
|
|
31
|
+
return "- Call `calibrate()` once during setup, before `read()`.";
|
|
406
32
|
}
|
|
407
33
|
}
|
|
408
34
|
|
|
409
|
-
console.log(agentHelp(new
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
Output:
|
|
413
|
-
|
|
414
|
-
```markdown
|
|
415
|
-
# RateLimiter
|
|
416
|
-
|
|
417
|
-
## Usage
|
|
418
|
-
|
|
419
|
-
- Create with `new RateLimiter(maxRequests)`.
|
|
420
|
-
- Call `acquire()` before making a request.
|
|
421
|
-
- Call `release()` after the request completes.
|
|
422
|
-
|
|
423
|
-
## Limits
|
|
424
|
-
|
|
425
|
-
- Default max is 100 concurrent requests.
|
|
426
|
-
- Exceeding the limit blocks until a slot opens.
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
A warning is written to stderr noting that `agentNotes()` is ignored.
|
|
430
|
-
|
|
431
|
-
### Example 4: Any class, no setup
|
|
432
|
-
|
|
433
|
-
```ts
|
|
434
|
-
import { agentHelp } from "agent-readable-ts";
|
|
435
|
-
|
|
436
|
-
class Cache {
|
|
437
|
-
get(key: string): unknown {
|
|
438
|
-
return undefined;
|
|
439
|
-
}
|
|
440
|
-
set(key: string, value: unknown): void {}
|
|
441
|
-
clear(): void {}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
console.log(agentHelp(new Cache()));
|
|
445
|
-
```
|
|
446
|
-
|
|
447
|
-
Output:
|
|
448
|
-
|
|
449
|
-
```markdown
|
|
450
|
-
# Cache
|
|
451
|
-
|
|
452
|
-
## Public API
|
|
453
|
-
|
|
454
|
-
- `clear()` method
|
|
455
|
-
- `get(key)` method
|
|
456
|
-
- `set(key, value)` method
|
|
457
|
-
|
|
458
|
-
## Agent usage rules
|
|
459
|
-
|
|
460
|
-
- Prefer the public API listed above.
|
|
461
|
-
- Do not use private, protected, underscored, or internal members.
|
|
462
|
-
- Do not invent unsupported behavior.
|
|
463
|
-
- If usage is ambiguous, prefer the simplest documented usage pattern.
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
### Example 5: Functions and bound methods
|
|
467
|
-
|
|
468
|
-
```ts
|
|
469
|
-
import { agentHelp } from "agent-readable-ts";
|
|
470
|
-
|
|
471
|
-
function connect(host: string, port: number): void {}
|
|
472
|
-
|
|
473
|
-
class Runner {
|
|
474
|
-
execute(command: string): number {
|
|
475
|
-
return 0;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
const runner = new Runner();
|
|
480
|
-
|
|
481
|
-
console.log(agentHelp(connect));
|
|
482
|
-
console.log(agentHelp(runner.execute.bind(runner)));
|
|
35
|
+
console.log(agentHelp(new Sensor()));
|
|
483
36
|
```
|
|
484
37
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
````markdown
|
|
488
|
-
# connect
|
|
489
|
-
|
|
490
|
-
## Signature
|
|
38
|
+
## Install
|
|
491
39
|
|
|
492
|
-
```
|
|
493
|
-
|
|
40
|
+
```sh
|
|
41
|
+
npm install agent-readable-ts
|
|
494
42
|
```
|
|
495
43
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
- Call this function according to the signature above.
|
|
499
|
-
- Do not invent unsupported parameters, return values, side effects, or lifecycle behavior.
|
|
500
|
-
- Do not use private, underscored, or internal implementation details.
|
|
501
|
-
- If usage is ambiguous, prefer the simplest documented usage pattern.
|
|
502
|
-
````
|
|
503
|
-
|
|
504
|
-
Output for the bound method:
|
|
44
|
+
For one-off CLI use:
|
|
505
45
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
```ts
|
|
512
|
-
execute(arg0)
|
|
46
|
+
```sh
|
|
47
|
+
npx agent-readable-ts commander
|
|
48
|
+
npm exec -- agent-readable-ts commander:Command
|
|
49
|
+
pnpm dlx agent-readable-ts ./src/widget.ts:Widget
|
|
513
50
|
```
|
|
514
51
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
- Call this function according to the signature above.
|
|
518
|
-
- Do not invent unsupported parameters, return values, side effects, or lifecycle behavior.
|
|
519
|
-
- Do not use private, underscored, or internal implementation details.
|
|
520
|
-
- If usage is ambiguous, prefer the simplest documented usage pattern.
|
|
521
|
-
````
|
|
522
|
-
|
|
523
|
-
## Warning output
|
|
52
|
+
See [Getting Started](docs/getting-started.md) for full install and CLI usage.
|
|
524
53
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
```ts
|
|
528
|
-
import { setWarnOutput, getWarnOutput } from "agent-readable-ts";
|
|
529
|
-
|
|
530
|
-
// Redirect to a custom sink
|
|
531
|
-
setWarnOutput((chunk: string) => {
|
|
532
|
-
console.log("[WARN]", chunk.trim());
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
// Or use an object with a write method
|
|
536
|
-
setWarnOutput({ write(chunk: string) { /* handle */ } });
|
|
537
|
-
|
|
538
|
-
// Silence warnings
|
|
539
|
-
setWarnOutput(null);
|
|
540
|
-
|
|
541
|
-
// Restore default
|
|
542
|
-
setWarnOutput(process.stderr);
|
|
543
|
-
```
|
|
54
|
+
## Documentation
|
|
544
55
|
|
|
545
|
-
|
|
56
|
+
- [Getting Started](docs/getting-started.md)
|
|
57
|
+
- [Why agent-readable-ts?](docs/why.md)
|
|
58
|
+
- [Examples](docs/examples.md)
|
|
59
|
+
- [Authoring Notes](docs/authoring.md)
|
|
60
|
+
- [FAQ](docs/faq.md)
|
|
546
61
|
|
|
547
|
-
|
|
62
|
+
## Other Languages
|
|
548
63
|
|
|
549
|
-
- **
|
|
550
|
-
|
|
551
|
-
- **CLI with `.ts` source**: full types are extracted by parsing the source file with the TypeScript compiler API.
|
|
552
|
-
- **CLI with `.js`/`.mjs`/`.cjs` files**: types are extracted from adjacent `.d.ts`/`.d.mts`/`.d.cts` declaration files if present (covers published packages).
|
|
553
|
-
- **Library API (`agentHelp()`)**: no type information — only runtime parameter names and arity.
|
|
554
|
-
- **No per-method descriptions.** Authors convey prose through `agentNotes()` or by implementing `agentHelp()`.
|
|
555
|
-
- **Constructors are not invoked** during introspection. Construction guidance belongs in notes.
|
|
556
|
-
- **Instance fields** can only be discovered from an actual instance or plain object, not from a class constructor.
|
|
557
|
-
- **Getters are not invoked** during introspection.
|
|
558
|
-
- **TypeScript `private` and `protected`** are compile-time constructs. The library excludes names starting with `_` but cannot perfectly detect visibility at runtime.
|
|
559
|
-
- **JavaScript `#private` fields and methods** are not reflectable and never appear in output.
|
|
560
|
-
- **Module-level documentation** is not supported.
|
|
561
|
-
- **Dynamic package import or CLI-based introspection** is intentionally omitted.
|
|
64
|
+
- **Python:** [agent-readable](https://github.com/zydo/agent-readable) provides
|
|
65
|
+
the same idea for Python packages and classes.
|
|
562
66
|
|
|
563
67
|
## License
|
|
564
68
|
|
|
@@ -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,59 @@
|
|
|
1
|
+
# FAQ
|
|
2
|
+
|
|
3
|
+
## Which Node versions are supported?
|
|
4
|
+
|
|
5
|
+
Node 20 or newer.
|
|
6
|
+
|
|
7
|
+
## Should I use the library API or the CLI?
|
|
8
|
+
|
|
9
|
+
Use `agentHelp(target)` when the target is already loaded in your program.
|
|
10
|
+
|
|
11
|
+
Use the CLI when you want better TypeScript signatures from source files or
|
|
12
|
+
declaration files:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npx agent-readable-ts ./src/widget.ts:Widget
|
|
16
|
+
npx agent-readable-ts commander:Command
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Can runtime reflection recover TypeScript types?
|
|
20
|
+
|
|
21
|
+
No. TypeScript types, interfaces, overloads, generic parameters, return types,
|
|
22
|
+
and doc comments are erased from compiled JavaScript.
|
|
23
|
+
|
|
24
|
+
The CLI can recover more type information by parsing `.ts` files or adjacent
|
|
25
|
+
declaration files.
|
|
26
|
+
|
|
27
|
+
## Why do some parameters show up as `arg0`?
|
|
28
|
+
|
|
29
|
+
Parameter names come from `Function.prototype.toString()` when possible. Native
|
|
30
|
+
functions, bound functions, destructured parameters, and some compiled output do
|
|
31
|
+
not preserve useful names, so the library falls back to `arg0`, `arg1`, and so
|
|
32
|
+
on.
|
|
33
|
+
|
|
34
|
+
## Are constructors or getters invoked?
|
|
35
|
+
|
|
36
|
+
No. Constructors are not called during introspection, and getters are not
|
|
37
|
+
invoked.
|
|
38
|
+
|
|
39
|
+
## Are private members shown?
|
|
40
|
+
|
|
41
|
+
JavaScript `#private` fields and methods are not reflectable and never appear.
|
|
42
|
+
|
|
43
|
+
TypeScript `private` and `protected` are compile-time constructs. The library
|
|
44
|
+
excludes names starting with `_`, but runtime JavaScript cannot perfectly detect
|
|
45
|
+
TypeScript visibility.
|
|
46
|
+
|
|
47
|
+
## Does the CLI fetch packages automatically?
|
|
48
|
+
|
|
49
|
+
No. Missing packages are only fetched when you pass `--install`.
|
|
50
|
+
|
|
51
|
+
Fetched packages go into an isolated cache and are installed with
|
|
52
|
+
`--ignore-scripts`. See [Getting Started](getting-started.md#on-demand-package-fetching).
|
|
53
|
+
|
|
54
|
+
## Is this the same as the Python package?
|
|
55
|
+
|
|
56
|
+
It is the TypeScript and JavaScript sibling of
|
|
57
|
+
[agent-readable](https://github.com/zydo/agent-readable). The shared idea is the
|
|
58
|
+
same: inspect the current API surface and author-provided usage rules before
|
|
59
|
+
coding against an unfamiliar target.
|
|
@@ -0,0 +1,94 @@
|
|
|
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 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, local JavaScript files, and local
|
|
32
|
+
TypeScript files.
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
npx agent-readable-ts commander
|
|
36
|
+
npx agent-readable-ts commander:Command
|
|
37
|
+
npx agent-readable-ts ./src/widget.ts:Widget
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`commander` is only an example target. Use any trusted installed package, local
|
|
41
|
+
module, or local TypeScript file.
|
|
42
|
+
|
|
43
|
+
Usage:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
agent-readable-ts [--install] <package-name>[:<export-name>]
|
|
47
|
+
agent-readable-ts <module-path>[:<export-name>]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- `package-name`: an installed npm package, such as `commander`, `pino`, or
|
|
51
|
+
`@scope/package`.
|
|
52
|
+
- `module-path`: a `.js`, `.mjs`, `.cjs`, or `.ts` file path relative to the
|
|
53
|
+
current directory.
|
|
54
|
+
- `export-name`: the named export to document. Use dots for nested access, such
|
|
55
|
+
as `Things.Helper`.
|
|
56
|
+
- `--install`: allow the CLI to fetch a package on demand when it is not
|
|
57
|
+
installed locally.
|
|
58
|
+
|
|
59
|
+
If no export name is given for a package, all exports are listed. If no export
|
|
60
|
+
name is given for a file, the module namespace object is documented.
|
|
61
|
+
|
|
62
|
+
`.ts` files require `tsx`. It is included as a dev dependency in this repo, and
|
|
63
|
+
`npx` resolves it automatically when running from this package.
|
|
64
|
+
|
|
65
|
+
## One-Off Execution
|
|
66
|
+
|
|
67
|
+
Use one of these when you do not want to add a dependency to the current project:
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
npx agent-readable-ts commander
|
|
71
|
+
npm exec -- agent-readable-ts commander:Command
|
|
72
|
+
pnpm dlx agent-readable-ts ./src/widget.ts:Widget
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## On-Demand Package Fetching
|
|
76
|
+
|
|
77
|
+
Packages already installed in the current project load directly. For anything
|
|
78
|
+
else, the CLI refuses to fetch unless `--install` is passed:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
npx agent-readable-ts --install left-pad
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Fetched packages go into `~/.cache/agent-readable-ts`, or the directory named by
|
|
85
|
+
`AGENT_READABLE_CACHE`. They are never installed into the current project.
|
|
86
|
+
|
|
87
|
+
The install uses `npm install --ignore-scripts`, so package lifecycle scripts are
|
|
88
|
+
not run. Cached packages load offline without requiring `--install` again.
|
|
89
|
+
|
|
90
|
+
## Security
|
|
91
|
+
|
|
92
|
+
The CLI imports packages and local modules in order to inspect them. Importing a
|
|
93
|
+
module executes its top-level code. Only inspect packages and files you trust to
|
|
94
|
+
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-readable-ts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
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",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"agent-readable-ts": "dist/src/cli.js"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
|
+
"docs",
|
|
20
21
|
"dist/src"
|
|
21
22
|
],
|
|
22
23
|
"scripts": {
|