@consultancy-outfit/ai-draftsman-cli 1.1.3 → 1.3.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.
Files changed (3) hide show
  1. package/README.md +179 -105
  2. package/dist/index.js +1406 -351
  3. package/package.json +44 -44
package/README.md CHANGED
@@ -1,105 +1,179 @@
1
- # AI Draftsman CLI
2
-
3
- Standalone Node.js/TypeScript CLI for the AI Draftsman platform.
4
-
5
- ## Requirements
6
-
7
- - Node.js 20+
8
- - npm
9
-
10
- ## Install dependencies
11
-
12
- ```bash
13
- npm install
14
- ```
15
-
16
- ## Run from source
17
-
18
- Interactive default flow, Claude-Code style:
19
-
20
- ```bash
21
- npm run dev
22
- ```
23
-
24
- The CLI now defaults to:
25
- - backend URL: `https://dev-api.aidraftsman.ai/`
26
- - frontend URL: `https://dev-b2b.aidraftsman.ai/`
27
- - browser login if you are not authenticated yet
28
- - agent/model selection launcher after login, instead of asking for a base URL
29
-
30
- Examples:
31
-
32
- ```bash
33
- npm run dev -- auth login
34
- npm run dev -- auth status
35
- npm run dev
36
- npm run dev -- agents list
37
- npm run dev -- agents run AGENT_ID --message "Summarize this project"
38
- npm run dev -- chat complete --model gpt-4o-mini --message "Hello"
39
- npm run dev -- conversations create --agent AGENT_ID
40
- npm run dev -- conversations send CONVERSATION_ID --message "Continue the work"
41
- npm run dev -- messages list CONVERSATION_ID
42
- npm run dev -- session exec --model agent:AGENT_ID --message "Plan the next step"
43
- npm run dev -- session start --model agent:AGENT_ID --durable
44
- npm run dev -- session resume CONVERSATION_ID --model agent:AGENT_ID
45
- ```
46
-
47
- ## Build
48
-
49
- ```bash
50
- npm run build
51
- ```
52
-
53
- ## Install globally on your system
54
-
55
- From npm:
56
-
57
- ```bash
58
- npm install -g @consultancy-outfit/ai-draftsman-cli
59
- ```
60
-
61
- Or from this project folder:
62
-
63
- ```bash
64
- npm install
65
- npm run build
66
- npm install -g .
67
- ```
68
-
69
- Then use either command:
70
-
71
- ```bash
72
- aidraftsman --help
73
- ad --help
74
- ```
75
-
76
- ## Windows PowerShell examples
77
-
78
- ```powershell
79
- npm install
80
- npm run build
81
- npm install -g .
82
- ad
83
- ad auth login
84
- ad agents list
85
- ad session start --model agent:AGENT_ID --durable
86
- ```
87
-
88
- ## Notes
89
-
90
- - `session start --durable` creates a durable conversation when the model is `agent:<id>`.
91
- - `session resume <conversationId> --model agent:<id>` continues by sending MCP messages to that conversation.
92
- - Current `--stream` support is terminal-style rendering built on one-shot responses, not full token streaming yet.
93
-
94
- ## Images
95
-
96
- Attach images (png, jpg, gif, webp; up to 5 MB each) in any of these ways:
97
-
98
- ```powershell
99
- ad -i screenshot.png "what is wrong with this layout?" # interactive, first prompt
100
- ad -p -i a.png -i b.png "compare these two" # print mode
101
- ad "match this design: @mockup.png" # an @path to an image is attached too
102
- ad chat complete --model agent:AGENT_ID --image shot.png --message "describe this"
103
- ```
104
-
105
- The gateway must accept OpenAI-style `image_url` content parts, and the chosen model must support vision.
1
+ # AI Draftsman CLI
2
+
3
+ Standalone Node.js/TypeScript CLI for the AI Draftsman platform.
4
+
5
+ ## Requirements
6
+
7
+ - Node.js 20+
8
+ - npm
9
+
10
+ ## Install dependencies
11
+
12
+ ```bash
13
+ npm install
14
+ ```
15
+
16
+ ## Run from source
17
+
18
+ Interactive default flow, Claude-Code style:
19
+
20
+ ```bash
21
+ npm run dev
22
+ ```
23
+
24
+ The CLI now defaults to:
25
+ - backend URL: `https://dev-api.aidraftsman.ai/`
26
+ - frontend URL: `https://dev-b2b.aidraftsman.ai/`
27
+ - browser login if you are not authenticated yet
28
+ - agent/model selection launcher after login, instead of asking for a base URL
29
+
30
+ Examples:
31
+
32
+ ```bash
33
+ npm run dev -- auth login
34
+ npm run dev -- auth status
35
+ npm run dev
36
+ npm run dev -- agents list
37
+ npm run dev -- agents run AGENT_ID --message "Summarize this project"
38
+ npm run dev -- chat complete --model gpt-4o-mini --message "Hello"
39
+ npm run dev -- conversations create --agent AGENT_ID
40
+ npm run dev -- conversations send CONVERSATION_ID --message "Continue the work"
41
+ npm run dev -- messages list CONVERSATION_ID
42
+ npm run dev -- session exec --model agent:AGENT_ID --message "Plan the next step"
43
+ npm run dev -- session start --model agent:AGENT_ID --durable
44
+ npm run dev -- session resume CONVERSATION_ID --model agent:AGENT_ID
45
+ ```
46
+
47
+ ## Build
48
+
49
+ ```bash
50
+ npm run build
51
+ ```
52
+
53
+ ## Install globally on your system
54
+
55
+ From npm:
56
+
57
+ ```bash
58
+ npm install -g @consultancy-outfit/ai-draftsman-cli
59
+ ```
60
+
61
+ Or from this project folder:
62
+
63
+ ```bash
64
+ npm install
65
+ npm run build
66
+ npm install -g .
67
+ ```
68
+
69
+ Then use either command:
70
+
71
+ ```bash
72
+ aidraftsman --help
73
+ ad --help
74
+ ```
75
+
76
+ ## Windows PowerShell examples
77
+
78
+ ```powershell
79
+ npm install
80
+ npm run build
81
+ npm install -g .
82
+ ad
83
+ ad auth login
84
+ ad agents list
85
+ ad session start --model agent:AGENT_ID --durable
86
+ ```
87
+
88
+ ## Notes
89
+
90
+ - `session start --durable` creates a durable conversation when the model is `agent:<id>`.
91
+ - `session resume <conversationId> --model agent:<id>` continues by sending MCP messages to that conversation.
92
+ - Current `--stream` support is terminal-style rendering built on one-shot responses, not full token streaming yet.
93
+
94
+ ## Images
95
+
96
+ Attach images (png, jpg, gif, webp; up to 5 MB each) in any of these ways:
97
+
98
+ ```powershell
99
+ ad -i screenshot.png "what is wrong with this layout?" # interactive, first prompt
100
+ ad -p -i a.png -i b.png "compare these two" # print mode
101
+ ad "match this design: @mockup.png" # an @path to an image is attached too
102
+ ad chat complete --model agent:AGENT_ID --image shot.png --message "describe this"
103
+ ```
104
+
105
+ The gateway must accept OpenAI-style `image_url` content parts, and the chosen model must support vision.
106
+
107
+ ## Headless runs (`-p`) for scripts and the DevOps Bot SDK
108
+
109
+ `ad -p` can stand in for `claude -p`: the same flags, the same output events and the same hooks, so a
110
+ tool that drives Claude Code headless (the DevOps Bot SDK) can drive `ad` without a second code path.
111
+
112
+ ```bash
113
+ # One Claude Code-style JSON event per line: system init, assistant text / tool_use,
114
+ # user tool_result (with tool_use_result.filePath for a write), and a final result.
115
+ ad -p --output-format stream-json "fix the failing test" < /dev/null
116
+
117
+ # Grant tools up front: nobody is there to approve a prompt in a headless run.
118
+ # Claude Code names (Bash, Write, Edit, MultiEdit, WebFetch) or ad's own (bash, write_file …).
119
+ ad -p --permission-mode acceptEdits --allowedTools Bash WebFetch "update the workbook from public sources"
120
+ ad -p --allowedTools "Bash(git:*)" "WebFetch(domain:example.org)" "summarise the repo history"
121
+
122
+ # Run a Claude Code settings file's PreToolUse command hooks before every tool call.
123
+ ad -p --settings ./claude_settings.json "tidy the build output"
124
+
125
+ # Continue a headless conversation by the session id a run printed.
126
+ ad -p -r SESSION_ID "the tests still fail; fix them"
127
+ ```
128
+
129
+ - **Events.** Tools are named and shaped as Claude Code names them (`Bash {command}`, `Write {file_path, content}`,
130
+ `Edit {file_path, old_string, new_string}`, `Read`, `Grep`, `Glob`, `WebFetch {url}`, `Task`), with absolute
131
+ `file_path`s. A sub-agent's own tool calls carry `parent_tool_use_id`. Every event has `session_id`. The `result`
132
+ event carries `usage.input_tokens` / `output_tokens` and `permission_denials` (`{tool_name, tool_use_id, tool_input}`);
133
+ a run that fails still ends with a `result` whose `is_error` is true.
134
+ - **`--allowedTools`.** `Bash(prefix:*)` grants commands that start with that prefix, never a chain (`;`, `&&`, `|` …).
135
+ A granted write tool still asks for a path outside the working directory, and plan mode still refuses changes.
136
+ Reads inside the working directory never need a grant. Unknown names are reported on stderr and ignored.
137
+ - **`--settings` hooks.** A file path or inline JSON. Each `hooks.PreToolUse[]` group's `matcher` (a regex over the
138
+ Claude Code tool name; empty or `*` for all) selects which `type: "command"` hooks run. A hook gets
139
+ `{session_id, cwd, hook_event_name: "PreToolUse", tool_name, tool_input}` on stdin. Exit code 2 blocks the call
140
+ (stderr is the reason); exit 0 with `hookSpecificOutput.permissionDecision` of `deny` blocks it (the reason goes
141
+ to the model) and `allow` lets it run without asking. A hook that fails or times out has no opinion. Hooks run for
142
+ sub-agents' calls too.
143
+ - `--output-format json` keeps its old one-object shape (`result`, `session_id`, `agent`, `usage`, `permission_denials`).
144
+
145
+ ## Your connectors (Gmail, Slack, Jira …)
146
+
147
+ The apps you connected in the AI Draftsman web app (**Connectors**) work from the CLI too: the agent gets
148
+ `list_connectors` and `call_connector`, and you can use them yourself with `ad connectors`. The platform holds the
149
+ credentials and performs each call **as you**, so nothing secret reaches this machine.
150
+
151
+ ```bash
152
+ ad login # a personal key: required, a workspace API key has no connectors
153
+ ad connectors # what you have connected
154
+ ad connectors slack # one connector and its actions (read / write)
155
+ ad connectors call slack chat.postMessage --params '{"channel":"#dev","text":"build is green"}'
156
+ ```
157
+
158
+ - **Only your connected apps are offered** — never the whole catalogue. Type `@` in the prompt and your connected
159
+ connectors appear first (`@slack connector · Slack`); picking one tells the agent to use that connector. With the
160
+ **Auto** agent you need not pick: the agent is told which connectors you have and chooses the right one itself.
161
+ `@name` works in `ad -p` prompts too. Set `AD_CONNECTORS=off` to hide them.
162
+ - Sign in again with `ad login` if you signed in before connectors were available: older keys are not tied to you.
163
+ - **Approvals.** Listing is free. A connector action asks first, per action (`Yes, and don't ask again for
164
+ slack/chat.postMessage`); `acceptEdits` does not cover it, plan mode refuses it, and `bypass` runs it.
165
+ - **Headless.** The tools appear in stream-json as `mcp__aidraftsman__list_connectors` /
166
+ `mcp__aidraftsman__call_connector`. Grant actions with `--allowedTools mcp__aidraftsman` (or
167
+ `mcp__aidraftsman__call_connector`, or `call_connector`).
168
+
169
+ ## Load and limits
170
+
171
+ The agent is shaped to be light on the shared gateway:
172
+
173
+ - **Sub-agents** run at most 3 at a time (`ad config set maxParallelSubagents 2`, or `AD_MAX_PARALLEL_SUBAGENTS`). A server that returns `capabilities.max_parallel` on `/v1/agents` caps it.
174
+ - **Sub-agent model:** under Auto, built-in sub-agents use `aidraftsman/auto-fast` when the server lists it in `/v1/models` (checked once per session), and Auto otherwise. Choose one yourself with `ad config set subagentModel <slug>` (or `AD_SUBAGENT_MODEL`); `inherit` keeps the main agent's model.
175
+ - **Step limits:** 40 model steps per turn (`maxSteps` / `AD_MAX_STEPS`) and 15 per sub-agent (`subagentMaxSteps` / `AD_SUBAGENT_MAX_STEPS`). An interactive session asks whether to continue; `ad -p` stops cleanly.
176
+ - **Headless runs** (`-p`, `--output-format json`, or stdout not a terminal) send `x-ad-automation: headless` and `x-ad-client-class: cli-automated`; interactive sessions send `x-ad-client-class: cli-interactive`. Every step of a turn sends the same `x-ad-run-id`; sub-agents add `x-ad-parent-run-id`.
177
+ - **Timing:** while a request has produced nothing the session shows how long it has waited for the first token, and any status the server sends. `/status` shows time to first token; `--debug` (or `AD_DEBUG=1`) prints it per request.
178
+ - **Updates:** an interactive session checks npm for a newer version at most once a day, in the background, and prints one line if there is one. Turn it off with `AD_NO_UPDATE_CHECK=1`.
179
+ - The server address lives in one place, `src/lib/config/defaults.ts`. `/doctor` prints it, with the region and served model when the gateway forwards them.