@inbrowser/agent 0.0.0-placeholder → 0.1.0
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/AGENTS.md +270 -0
- package/README.md +117 -2
- package/bin/agent.ts +10 -0
- package/dist/cli/commands/describe.d.ts +14 -0
- package/dist/cli/commands/describe.d.ts.map +1 -0
- package/dist/cli/commands/describe.js +179 -0
- package/dist/cli/commands/describe.js.map +1 -0
- package/dist/cli/commands/events.d.ts +21 -0
- package/dist/cli/commands/events.d.ts.map +1 -0
- package/dist/cli/commands/events.js +59 -0
- package/dist/cli/commands/events.js.map +1 -0
- package/dist/cli/commands/fleet.d.ts +15 -0
- package/dist/cli/commands/fleet.d.ts.map +1 -0
- package/dist/cli/commands/fleet.js +149 -0
- package/dist/cli/commands/fleet.js.map +1 -0
- package/dist/cli/commands/help.d.ts +15 -0
- package/dist/cli/commands/help.d.ts.map +1 -0
- package/dist/cli/commands/help.js +93 -0
- package/dist/cli/commands/help.js.map +1 -0
- package/dist/cli/commands/migrate.d.ts +27 -0
- package/dist/cli/commands/migrate.d.ts.map +1 -0
- package/dist/cli/commands/migrate.js +109 -0
- package/dist/cli/commands/migrate.js.map +1 -0
- package/dist/cli/commands/run.d.ts +38 -0
- package/dist/cli/commands/run.d.ts.map +1 -0
- package/dist/cli/commands/run.js +535 -0
- package/dist/cli/commands/run.js.map +1 -0
- package/dist/cli/commands/schema.d.ts +8 -0
- package/dist/cli/commands/schema.d.ts.map +1 -0
- package/dist/cli/commands/schema.js +12 -0
- package/dist/cli/commands/schema.js.map +1 -0
- package/dist/cli/commands/serve.d.ts +39 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/serve.js +65 -0
- package/dist/cli/commands/serve.js.map +1 -0
- package/dist/cli/commands/undo.d.ts +36 -0
- package/dist/cli/commands/undo.d.ts.map +1 -0
- package/dist/cli/commands/undo.js +132 -0
- package/dist/cli/commands/undo.js.map +1 -0
- package/dist/cli/fixtures.d.ts +17 -0
- package/dist/cli/fixtures.d.ts.map +1 -0
- package/dist/cli/fixtures.js +107 -0
- package/dist/cli/fixtures.js.map +1 -0
- package/dist/cli/hardening.d.ts +39 -0
- package/dist/cli/hardening.d.ts.map +1 -0
- package/dist/cli/hardening.js +68 -0
- package/dist/cli/hardening.js.map +1 -0
- package/dist/cli/index.d.ts +28 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +19 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/llm/openrouter.d.ts +33 -0
- package/dist/cli/llm/openrouter.d.ts.map +1 -0
- package/dist/cli/llm/openrouter.js +285 -0
- package/dist/cli/llm/openrouter.js.map +1 -0
- package/dist/cli/main.d.ts +32 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +106 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/output.d.ts +36 -0
- package/dist/cli/output.d.ts.map +1 -0
- package/dist/cli/output.js +95 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/cli/parse.d.ts +26 -0
- package/dist/cli/parse.d.ts.map +1 -0
- package/dist/cli/parse.js +160 -0
- package/dist/cli/parse.js.map +1 -0
- package/dist/cli/session-log.d.ts +34 -0
- package/dist/cli/session-log.d.ts.map +1 -0
- package/dist/cli/session-log.js +52 -0
- package/dist/cli/session-log.js.map +1 -0
- package/dist/cli/spec.d.ts +62 -0
- package/dist/cli/spec.d.ts.map +1 -0
- package/dist/cli/spec.js +510 -0
- package/dist/cli/spec.js.map +1 -0
- package/dist/cli/ui/RunView.d.ts +134 -0
- package/dist/cli/ui/RunView.d.ts.map +1 -0
- package/dist/cli/ui/RunView.js +341 -0
- package/dist/cli/ui/RunView.js.map +1 -0
- package/dist/events/codec.d.ts +79 -0
- package/dist/events/codec.d.ts.map +1 -0
- package/dist/events/codec.js +142 -0
- package/dist/events/codec.js.map +1 -0
- package/dist/events/log-core.d.ts +76 -0
- package/dist/events/log-core.d.ts.map +1 -0
- package/dist/events/log-core.js +73 -0
- package/dist/events/log-core.js.map +1 -0
- package/dist/events/log.d.ts +60 -0
- package/dist/events/log.d.ts.map +1 -0
- package/dist/events/log.js +193 -0
- package/dist/events/log.js.map +1 -0
- package/dist/events/replay.d.ts +106 -0
- package/dist/events/replay.d.ts.map +1 -0
- package/dist/events/replay.js +137 -0
- package/dist/events/replay.js.map +1 -0
- package/dist/events/wrap.d.ts +100 -0
- package/dist/events/wrap.d.ts.map +1 -0
- package/dist/events/wrap.js +141 -0
- package/dist/events/wrap.js.map +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/llm-adapter.d.ts +96 -0
- package/dist/llm-adapter.d.ts.map +1 -0
- package/dist/llm-adapter.js +132 -0
- package/dist/llm-adapter.js.map +1 -0
- package/dist/mcp/serve.d.ts +70 -0
- package/dist/mcp/serve.d.ts.map +1 -0
- package/dist/mcp/serve.js +154 -0
- package/dist/mcp/serve.js.map +1 -0
- package/dist/metrics/runs.d.ts +58 -0
- package/dist/metrics/runs.d.ts.map +1 -0
- package/dist/metrics/runs.js +99 -0
- package/dist/metrics/runs.js.map +1 -0
- package/dist/metrics.d.ts +38 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +123 -0
- package/dist/metrics.js.map +1 -0
- package/dist/node.d.ts +22 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +22 -0
- package/dist/node.js.map +1 -0
- package/dist/session.d.ts +10 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +179 -0
- package/dist/session.js.map +1 -0
- package/dist/storage.d.ts +14 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +58 -0
- package/dist/storage.js.map +1 -0
- package/dist/strategy.d.ts +26 -0
- package/dist/strategy.d.ts.map +1 -0
- package/dist/strategy.js +200 -0
- package/dist/strategy.js.map +1 -0
- package/dist/tools.d.ts +26 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +129 -0
- package/dist/tools.js.map +1 -0
- package/dist/types/agent.d.ts +94 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +17 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/capabilities.d.ts +17 -0
- package/dist/types/capabilities.d.ts.map +1 -0
- package/dist/types/capabilities.js +13 -0
- package/dist/types/capabilities.js.map +1 -0
- package/dist/types/chat.d.ts +74 -0
- package/dist/types/chat.d.ts.map +1 -0
- package/dist/types/chat.js +10 -0
- package/dist/types/chat.js.map +1 -0
- package/dist/types/events.d.ts +115 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +30 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/llm.d.ts +89 -0
- package/dist/types/llm.d.ts.map +1 -0
- package/dist/types/llm.js +12 -0
- package/dist/types/llm.js.map +1 -0
- package/dist/types/metrics.d.ts +34 -0
- package/dist/types/metrics.d.ts.map +1 -0
- package/dist/types/metrics.js +10 -0
- package/dist/types/metrics.js.map +1 -0
- package/dist/types/observer.d.ts +41 -0
- package/dist/types/observer.d.ts.map +1 -0
- package/dist/types/observer.js +41 -0
- package/dist/types/observer.js.map +1 -0
- package/dist/types/project-context.d.ts +18 -0
- package/dist/types/project-context.d.ts.map +1 -0
- package/dist/types/project-context.js +11 -0
- package/dist/types/project-context.js.map +1 -0
- package/dist/types/runtime.d.ts +71 -0
- package/dist/types/runtime.d.ts.map +1 -0
- package/dist/types/runtime.js +21 -0
- package/dist/types/runtime.js.map +1 -0
- package/dist/types/session.d.ts +103 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +11 -0
- package/dist/types/session.js.map +1 -0
- package/dist/types/storage.d.ts +20 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/storage.js +41 -0
- package/dist/types/storage.js.map +1 -0
- package/dist/types/strategy.d.ts +76 -0
- package/dist/types/strategy.d.ts.map +1 -0
- package/dist/types/strategy.js +10 -0
- package/dist/types/strategy.js.map +1 -0
- package/dist/types/tools.d.ts +136 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +11 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/types/trace.d.ts +125 -0
- package/dist/types/trace.d.ts.map +1 -0
- package/dist/types/trace.js +24 -0
- package/dist/types/trace.js.map +1 -0
- package/dist/types/workspace.d.ts +29 -0
- package/dist/types/workspace.d.ts.map +1 -0
- package/dist/types/workspace.js +18 -0
- package/dist/types/workspace.js.map +1 -0
- package/package.json +45 -14
- package/skills/agent-cli.md +218 -0
- package/index.js +0 -2
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: agent-cli
|
|
3
|
+
description: Drive the `@inbrowser/agent` CLI to run headless agent sessions, fleets, and emit NDJSON event streams + per-session metrics.
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
applies_to:
|
|
6
|
+
- "@inbrowser/agent"
|
|
7
|
+
- command: agent
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Skill: drive the `agent` CLI
|
|
11
|
+
|
|
12
|
+
This skill teaches an AI agent how to invoke `agent` correctly the
|
|
13
|
+
first time, without trial-and-error.
|
|
14
|
+
|
|
15
|
+
## Entry points
|
|
16
|
+
|
|
17
|
+
- `agent run` — single session. Use when you have one task to drive.
|
|
18
|
+
- `agent fleet` — N concurrent sessions. Use for stress / isolation
|
|
19
|
+
testing or batch processing.
|
|
20
|
+
- `agent describe` — JSON description of commands, events, scenarios.
|
|
21
|
+
- `agent schema` — full CliSpec JSON.
|
|
22
|
+
- `agent help [command]` — structured help in non-TTY, prose in TTY.
|
|
23
|
+
|
|
24
|
+
## Step-by-step: run a single session
|
|
25
|
+
|
|
26
|
+
1. **Discover the schema once per session**:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
agent schema > /tmp/agent-schema.json
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Cache `commands[*].options` keyed by `name` — use that to drive
|
|
33
|
+
your own argument validation.
|
|
34
|
+
|
|
35
|
+
2. **Build the payload as JSON**, not as flag args, for any input
|
|
36
|
+
containing newlines, quotes, or > 100 chars:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"prompt": "Refactor the workspace rules to be owner-only.",
|
|
41
|
+
"scenario": "write-rules",
|
|
42
|
+
"maxTurns": 4
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
3. **Dry-run first**:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
echo "$PAYLOAD" | agent run --json - --dry-run
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The response is one event: `{"type":"dry_run_plan", "sessionId":..., ...}`.
|
|
53
|
+
If the plan looks right, drop `--dry-run` and run for real.
|
|
54
|
+
|
|
55
|
+
4. **Stream the NDJSON**. Each line is a JSON event. Track:
|
|
56
|
+
|
|
57
|
+
- `session_start` — record `sessionId` for log lookup
|
|
58
|
+
- `tool_call` / `tool_result` — observe what the agent did
|
|
59
|
+
- `turn_end` — per-turn metrics
|
|
60
|
+
- `session_end` — TOTALS go here; this is the row to save
|
|
61
|
+
|
|
62
|
+
5. **Read totals from the log**, not from the stream tail — the log
|
|
63
|
+
is durable:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
SESSION=$(jq -r 'select(.type=="session_start") | .sessionId' < stream.ndjson | head -1)
|
|
67
|
+
tail -1 ~/.pyric/sessions/$SESSION.ndjson | jq '.totals'
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Step-by-step: run a fleet for isolation testing
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
agent fleet --size 10
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The `fleet_summary` event is the row to inspect. If `isolated: false`,
|
|
77
|
+
the test failed — at least one session's workspace state leaked
|
|
78
|
+
across the boundary.
|
|
79
|
+
|
|
80
|
+
## Field filtering for token economy
|
|
81
|
+
|
|
82
|
+
If you only need to know whether tool calls succeeded, ask for less:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
agent run --json - --fields ts,type,sessionId,callId,ok,summary < payload.json
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
You'll skip the chat chunks entirely.
|
|
89
|
+
|
|
90
|
+
## Input hardening cheat-sheet
|
|
91
|
+
|
|
92
|
+
The parser will reject (exit 64):
|
|
93
|
+
|
|
94
|
+
| Field type | Rejected if it contains |
|
|
95
|
+
| ---------- | --------------------------------------------- |
|
|
96
|
+
| any string | control chars (`\x00`–`\x1F`, `\x7F`) |
|
|
97
|
+
| paths / ids | `..` segments, `%2e`, `?`, `#` |
|
|
98
|
+
| oversized | exceeding the option's `maxLength` |
|
|
99
|
+
| ids | not matching `^[a-zA-Z0-9_.-]+$` (session-id) |
|
|
100
|
+
|
|
101
|
+
To avoid retries, pre-validate against `option.validate` in the
|
|
102
|
+
schema before invoking.
|
|
103
|
+
|
|
104
|
+
## Event sourcing — audit + undo
|
|
105
|
+
|
|
106
|
+
Every tool wrapped in `wrapMutating()` (from the library surface)
|
|
107
|
+
emits typed events to `~/.pyric/projects/<projectId>/events.ndjson`.
|
|
108
|
+
The CLI surfaces them via two read-only and one mutating subcommand:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# Audit
|
|
112
|
+
agent events --project my-app # full log
|
|
113
|
+
agent events --project my-app --phase commit # just the committed ones
|
|
114
|
+
agent events --project my-app --tool writeRules
|
|
115
|
+
agent events --project my-app --session sess-x
|
|
116
|
+
agent events --project my-app --since 2026-05-11T00:00Z --until 2026-05-12T00:00Z
|
|
117
|
+
|
|
118
|
+
# Undo (plan first, then commit)
|
|
119
|
+
agent undo --project my-app --event <id> --dry-run
|
|
120
|
+
agent undo --project my-app --event <id>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The undo flow records a `rollback` event in the log but **does not
|
|
124
|
+
invoke the reverse tool** — the host (your agent or playground)
|
|
125
|
+
reads the rollback event and dispatches the recorded `reverseOp.tool`
|
|
126
|
+
against its own `ToolDispatch`. The CLI is a controller surface; it
|
|
127
|
+
deliberately does not bundle a Firebase admin runtime.
|
|
128
|
+
|
|
129
|
+
Workflow when you're about to mutate something risky:
|
|
130
|
+
|
|
131
|
+
1. Run the tool normally (the wrapping is transparent — same args).
|
|
132
|
+
2. Find the resulting commit event id via `agent events --project …
|
|
133
|
+
--tool X --phase commit | tail -1 | jq -r .id`.
|
|
134
|
+
3. If something looks wrong, `agent undo --project … --event <id>
|
|
135
|
+
--dry-run` to see the reverse plan.
|
|
136
|
+
4. If the plan is right, drop `--dry-run`. Host picks up the rollback.
|
|
137
|
+
|
|
138
|
+
Event-specific anti-patterns:
|
|
139
|
+
|
|
140
|
+
- ✗ Don't manually edit the NDJSON log. It's append-only; readers
|
|
141
|
+
treat unknown lines as corrupt and skip them.
|
|
142
|
+
- ✗ Don't reuse the same event id across calls. Generated ids are
|
|
143
|
+
time-prefixed base36 and globally sortable; don't override.
|
|
144
|
+
- ✗ Don't expect `agent undo` to roll back service enablements,
|
|
145
|
+
bucket creations, or other one-way operations. They emit with
|
|
146
|
+
`reversible: false` and `agent undo` refuses up front.
|
|
147
|
+
|
|
148
|
+
## Forward replay (dev → prod migrations)
|
|
149
|
+
|
|
150
|
+
The same log that powers `agent undo` can replay forwards against a
|
|
151
|
+
production dispatch. Use case: agent explored a data shape against
|
|
152
|
+
the simulator locally; you want to apply those exact mutations to
|
|
153
|
+
live Firestore.
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# Plan: what would replay?
|
|
157
|
+
agent migrate --project my-app
|
|
158
|
+
|
|
159
|
+
# Filter from an anchor + restrict tools.
|
|
160
|
+
agent migrate --project my-app --since-event <id> --tools setDoc,writeRules
|
|
161
|
+
|
|
162
|
+
# Record an intent marker the host's pipeline can pick up.
|
|
163
|
+
agent migrate --project my-app --record
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The CLI does NOT run the tools (same controller/runtime split as
|
|
167
|
+
`agent undo`). The host calls `replayEvents()` from `@inbrowser/agent`:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import { openEventLog, replayEvents } from '@inbrowser/agent';
|
|
171
|
+
|
|
172
|
+
const log = openEventLog({ projectId: 'my-app' });
|
|
173
|
+
const dispatch = /* your prod ToolDispatch wired to live services */;
|
|
174
|
+
|
|
175
|
+
for await (const ev of replayEvents({ log, dispatch, toolContext })) {
|
|
176
|
+
switch (ev.type) {
|
|
177
|
+
case 'applied': /* event ev.event was re-executed in prod */ break;
|
|
178
|
+
case 'skipped': /* ev.reason: already_applied | tool_denied | path_denied | legacy_no_args | conflict_skip */ break;
|
|
179
|
+
case 'error': /* ev.event + ev.message; loop continues to next */ break;
|
|
180
|
+
case 'done': /* ev.applied / skipped / errors totals */ break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Replay is idempotent. `replayEvents()` writes a `migrate_applied`
|
|
186
|
+
marker per success; re-runs skip already-marked events.
|
|
187
|
+
|
|
188
|
+
Workflow when migrating dev → prod:
|
|
189
|
+
|
|
190
|
+
1. **Plan locally:** `agent migrate --project dev | jq .tool | sort | uniq -c`
|
|
191
|
+
tells you what tools and how many you're about to fire in prod.
|
|
192
|
+
2. **Optionally narrow:** filter by `--since-event` (only what's new
|
|
193
|
+
since the last migration) or `--tools` (only the writes you trust).
|
|
194
|
+
3. **Record intent:** `agent migrate --project dev --record` writes a
|
|
195
|
+
`migrate_intent` event with the planned ids. Audit log entry.
|
|
196
|
+
4. **Run replay in the host:** the deploy script / specialized agent
|
|
197
|
+
invokes `replayEvents()` with its prod dispatch.
|
|
198
|
+
5. **Re-run if interrupted:** safe. Already-applied events are skipped.
|
|
199
|
+
|
|
200
|
+
Replay-specific anti-patterns:
|
|
201
|
+
|
|
202
|
+
- ✗ Don't replay against the SAME dispatch that emitted the events.
|
|
203
|
+
You'd re-record everything (recursive) and double-mutate.
|
|
204
|
+
- ✗ Don't skip the `--record` step in CI/CD — the intent marker is
|
|
205
|
+
the audit hook ("we did mean to apply this set on this day").
|
|
206
|
+
- ✗ Don't pass `legacyEventPolicy: 'abort'` unless you've audited the
|
|
207
|
+
log first. A single pre-args-field event will halt the migration.
|
|
208
|
+
|
|
209
|
+
## Anti-patterns
|
|
210
|
+
|
|
211
|
+
- ✗ Parsing `agent run` text output to recover totals — instead read
|
|
212
|
+
the last NDJSON line of the log file.
|
|
213
|
+
- ✗ Passing the prompt as a flag when it has quotes — use `--json -`.
|
|
214
|
+
- ✗ Using `--scenario echo` for tool flows — `echo` emits no tool
|
|
215
|
+
calls. Use `write-rules` (or the host's real LLM when running
|
|
216
|
+
inside the playground).
|
|
217
|
+
- ✗ Calling `run` repeatedly to "pre-warm" — each invocation is a
|
|
218
|
+
fresh session with no shared state.
|
package/index.js
DELETED