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
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
|
|
14
|
+
To let your coding agent automatically call `agentHelp()` before using an
|
|
15
|
+
unfamiliar API, install the companion skill:
|
|
19
16
|
|
|
20
17
|
```sh
|
|
21
|
-
|
|
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:
|
|
79
|
-
|
|
80
|
-
```sh
|
|
81
|
-
npx agent-readable-ts commander:Command
|
|
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,40 @@ 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.";
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
console.log(agentHelp(new RateLimiter()));
|
|
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;
|
|
31
|
+
return "- Call `calibrate()` once during setup, before `read()`.";
|
|
439
32
|
}
|
|
440
|
-
set(key: string, value: unknown): void {}
|
|
441
|
-
clear(): void {}
|
|
442
33
|
}
|
|
443
34
|
|
|
444
|
-
console.log(agentHelp(new
|
|
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
|
-
````
|
|
44
|
+
For one-off CLI use, two parallel series:
|
|
503
45
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
# execute
|
|
508
|
-
|
|
509
|
-
## Signature
|
|
510
|
-
|
|
511
|
-
```ts
|
|
512
|
-
execute(arg0)
|
|
46
|
+
```sh
|
|
47
|
+
npx agent-readable-ts commander # npm series
|
|
48
|
+
pnpm dlx agent-readable-ts commander # pnpm series
|
|
513
49
|
```
|
|
514
50
|
|
|
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
|
|
51
|
+
See [Getting Started](docs/getting-started.md) for both series, repeated-use installs, and full CLI usage.
|
|
524
52
|
|
|
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
|
-
```
|
|
53
|
+
## Documentation
|
|
544
54
|
|
|
545
|
-
|
|
55
|
+
- [Getting Started](docs/getting-started.md)
|
|
56
|
+
- [Why agent-readable-ts?](docs/why.md)
|
|
57
|
+
- [Examples](docs/examples.md)
|
|
58
|
+
- [Authoring Notes](docs/authoring.md)
|
|
59
|
+
- [FAQ](docs/faq.md)
|
|
546
60
|
|
|
547
|
-
|
|
61
|
+
## Other Languages
|
|
548
62
|
|
|
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.
|
|
63
|
+
- **Python:** [agent-readable](https://github.com/zydo/agent-readable) provides
|
|
64
|
+
the same idea for Python packages and classes.
|
|
562
65
|
|
|
563
66
|
## License
|
|
564
67
|
|
package/dist/src/cli.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { agentHelp } from "./index.js";
|
|
3
|
-
import { resolvePackageTypesPath, listPackageExports } from "./source-types.js";
|
|
4
|
-
import { parseSpecifier, isBarePackageName, splitPackageSpec, walkExportPath, loadTypeSigs, formatExportList, listRuntimeExports, loadPackage, } from "./packages.js";
|
|
3
|
+
import { resolvePackageTypesPath, listPackageExports, resolveBuiltinTypesPath } from "./source-types.js";
|
|
4
|
+
import { CliUsageError, parseCliArgs, parseSpecifier, isBarePackageName, splitPackageSpec, walkExportPath, loadTypeSigs, formatExportList, listRuntimeExports, loadPackage, } from "./packages.js";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
import { resolve } from "node:path";
|
|
7
7
|
import { readFileSync } from "node:fs";
|
|
8
8
|
function usage() {
|
|
9
9
|
process.stderr.write("Usage: agent-readable-ts [--install] <module-path>[:<export-name>]\n" +
|
|
10
10
|
" agent-readable-ts [--install] <package-name>[:<export-name>]\n" +
|
|
11
|
+
" agent-readable-ts node:<builtin>[:<export-name>]\n" +
|
|
11
12
|
"\n" +
|
|
12
13
|
"Options:\n" +
|
|
13
14
|
" --install Allow fetching a package on demand (with npm install) when it\n" +
|
|
@@ -41,6 +42,25 @@ async function handleFile(modulePath, exportName) {
|
|
|
41
42
|
const typeSigs = loadTypeSigs(absolutePath, leafName(exportName));
|
|
42
43
|
process.stdout.write(agentHelp(target, typeSigs));
|
|
43
44
|
}
|
|
45
|
+
// ── node: builtin handling ─────────────────────────────────────────────────────
|
|
46
|
+
async function handleBuiltin(modulePath, exportName) {
|
|
47
|
+
let mod;
|
|
48
|
+
try {
|
|
49
|
+
mod = (await import(modulePath));
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
fail(`Cannot import "${modulePath}": ${err instanceof Error ? err.message : String(err)}`);
|
|
53
|
+
}
|
|
54
|
+
// No export name: list all exports
|
|
55
|
+
if (!exportName) {
|
|
56
|
+
process.stdout.write(formatExportList(modulePath, listRuntimeExports(mod)));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const target = walkExportPath(mod, exportName);
|
|
60
|
+
const dtsPath = resolveBuiltinTypesPath(modulePath);
|
|
61
|
+
const typeSigs = dtsPath ? loadTypeSigs(dtsPath, leafName(exportName)) : undefined;
|
|
62
|
+
process.stdout.write(agentHelp(target, typeSigs));
|
|
63
|
+
}
|
|
44
64
|
// ── package-based handling ─────────────────────────────────────────────────────
|
|
45
65
|
async function handlePackage(spec, exportName, allowInstall) {
|
|
46
66
|
const { name } = splitPackageSpec(spec);
|
|
@@ -62,20 +82,13 @@ async function handlePackage(spec, exportName, allowInstall) {
|
|
|
62
82
|
process.stdout.write(agentHelp(target, typeSigs));
|
|
63
83
|
}
|
|
64
84
|
// ── main ───────────────────────────────────────────────────────────────────────
|
|
65
|
-
const args = process.argv.slice(2);
|
|
66
|
-
const allowInstall = args.includes("--install");
|
|
67
|
-
const positional = args.filter((arg) => arg !== "--install");
|
|
68
|
-
const unknownFlag = positional.find((arg) => arg.startsWith("--"));
|
|
69
|
-
if (unknownFlag) {
|
|
70
|
-
process.stderr.write(`Error: Unknown option "${unknownFlag}"\n`);
|
|
71
|
-
usage();
|
|
72
|
-
}
|
|
73
|
-
const specifier = positional[0];
|
|
74
|
-
if (!specifier)
|
|
75
|
-
usage();
|
|
76
85
|
try {
|
|
86
|
+
const { allowInstall, specifier } = parseCliArgs(process.argv.slice(2));
|
|
77
87
|
const { modulePath, exportName } = parseSpecifier(specifier);
|
|
78
|
-
if (
|
|
88
|
+
if (modulePath.startsWith("node:")) {
|
|
89
|
+
await handleBuiltin(modulePath, exportName);
|
|
90
|
+
}
|
|
91
|
+
else if (isBarePackageName(modulePath)) {
|
|
79
92
|
await handlePackage(modulePath, exportName, allowInstall);
|
|
80
93
|
}
|
|
81
94
|
else {
|
|
@@ -83,6 +96,10 @@ try {
|
|
|
83
96
|
}
|
|
84
97
|
}
|
|
85
98
|
catch (err) {
|
|
99
|
+
if (err instanceof CliUsageError) {
|
|
100
|
+
process.stderr.write(`Error: ${err.message}\n`);
|
|
101
|
+
usage();
|
|
102
|
+
}
|
|
86
103
|
fail(err instanceof Error ? err.message : String(err));
|
|
87
104
|
}
|
|
88
105
|
//# sourceMappingURL=cli.js.map
|
package/dist/src/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AACzG,OAAO,EACL,aAAa,EACb,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,SAAS,KAAK;IACZ,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,sEAAsE;QACtE,uEAAuE;QACvE,2DAA2D;QAC3D,IAAI;QACJ,YAAY;QACZ,8EAA8E;QAC9E,kEAAkE,CACnE,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,SAAS,IAAI,CAAC,OAAe;IAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,OAAO,IAAI,CAAC,CAAC;IAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,kFAAkF;AAElF,iFAAiF;AACjF,SAAS,QAAQ,CAAC,UAAyB;IACzC,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAC7B,MAAM,OAA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