@impact-ai/setup 0.0.0-stage → 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/LICENSE +202 -0
- package/NOTICE +6 -0
- package/README.md +105 -2
- package/bin/impact-ai-setup.js +14 -0
- package/package.json +27 -4
- package/src/agents.js +213 -0
- package/src/args.js +99 -0
- package/src/dotenv.js +122 -0
- package/src/main.js +562 -0
- package/src/processes.js +177 -0
- package/src/project.js +72 -0
- package/src/service.js +99 -0
- package/src/terminal.js +134 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,106 @@
|
|
|
1
|
-
#
|
|
1
|
+
# impact.ai setup command
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run it in your application's folder:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npx @impact-ai/setup
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
It connects the application to [impact.ai](https://impact.ai) in one sitting: you allow it in the browser, it writes one
|
|
10
|
+
ingest key to `.env`, the coding agent already on your computer adds the instrumentation, the application runs once, and
|
|
11
|
+
the command finishes when impact.ai has received its first trace and checked it.
|
|
12
|
+
|
|
13
|
+
## What it does
|
|
14
|
+
|
|
15
|
+
1. **Checks before anything.** In a git repository with uncommitted files it says how many and asks whether to go on.
|
|
16
|
+
When `.env` already holds `IMPACT_INGEST_KEY` it asks before replacing it. It finds the coding agent. Stopping at
|
|
17
|
+
any of these ends `Failed: stopped` with nothing changed and no sign-in.
|
|
18
|
+
2. **Signs in.** It starts a setup with the computer's name, the folder's name and the language its manifests show
|
|
19
|
+
(`pyproject.toml`, `requirements.txt` or `setup.py` for Python, `package.json` for JavaScript), opens the allow page
|
|
20
|
+
in the browser and prints its address too, for a computer without one. An Owner or Admin of the Workspace allows
|
|
21
|
+
it; denied, or nobody allowing within 10 minutes, ends `Failed: not allowed`.
|
|
22
|
+
3. **Writes the key.** `IMPACT_INGEST_KEY` and `IMPACT_INGEST_ENDPOINT` go to `.env` in the folder (a new `.env` is
|
|
23
|
+
readable by you only), and `.env` goes to `.gitignore` unless git already ignores it. It prints the Workspace, the
|
|
24
|
+
Product, the key's name and whether the Product keeps message text.
|
|
25
|
+
4. **Hands one task to the coding agent.** The task comes from impact.ai and holds no key. The agent runs once, in its
|
|
26
|
+
non-interactive mode, with the narrowest permissions that let it edit files and install packages in this folder
|
|
27
|
+
(below). It must not commit: a commit, or a switch of branch, fails the setup. When the agent says it could not
|
|
28
|
+
cover a library or language, the command changes nothing more and points you to the exporter route.
|
|
29
|
+
5. **Runs the application once.** It shows the command the agent found and runs it when you confirm, with the two
|
|
30
|
+
variables from `.env` in its environment.
|
|
31
|
+
6. **Waits for the trace.** It reads the setup's status every 3 seconds and prints the trace when it arrives, then
|
|
32
|
+
`Checked: 14 checks ran, nothing flagged` (or the checks that flagged) with the trace's address. An application that
|
|
33
|
+
keeps running, such as a server, is stopped at the end.
|
|
34
|
+
|
|
35
|
+
The ingest key goes to `.env` and to the run's environment only: never to the terminal (anything printed, the agent's
|
|
36
|
+
and the application's output included, has it replaced by `[ingest key]`), the agent's task or environment, a log, or a
|
|
37
|
+
commit.
|
|
38
|
+
|
|
39
|
+
## Requirements
|
|
40
|
+
|
|
41
|
+
* Node.js 22 or later. The command has no dependencies: it runs on Node.js's own modules.
|
|
42
|
+
* One coding agent, signed in: Claude Code (`claude`), Codex (`codex`) or Cursor's agent, which now ships as the Grok
|
|
43
|
+
Build CLI (`grok` 2.x). Claude Code is used when several are installed; `--agent` picks one. The legacy Cursor CLI
|
|
44
|
+
(`cursor-agent`) updates to it with `cursor-agent update --channel grok`.
|
|
45
|
+
* git, when the folder is a repository: the command reads where `HEAD` is and what is uncommitted, and writes nothing to
|
|
46
|
+
git.
|
|
47
|
+
|
|
48
|
+
## Options
|
|
49
|
+
|
|
50
|
+
| Option | |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `--url <origin>` | impact.ai's address; `IMPACT_URL` does the same. Without either, the production app. `https://` only, or `http://` on this computer |
|
|
53
|
+
| `--agent claude\|codex\|cursor` | the coding agent to use |
|
|
54
|
+
| `-y`, `--yes` | answer yes to every question, for a run without a terminal; without it and without a terminal, every question is answered no |
|
|
55
|
+
| `-h`, `--help`, `-v`, `--version` | |
|
|
56
|
+
|
|
57
|
+
`BROWSER` names the program that opens the allow page (`none`: only print it).
|
|
58
|
+
|
|
59
|
+
## Exit codes
|
|
60
|
+
|
|
61
|
+
| Code | |
|
|
62
|
+
|---|---|
|
|
63
|
+
| 0 | Checked: impact.ai received the trace and checked it |
|
|
64
|
+
| 3 | Set up, but no checked trace: no trace arrived within 15 minutes of the run starting, one arrived but was not checked yet, or impact.ai could not be reached while waiting |
|
|
65
|
+
| 1 | Failed: not allowed, stopped, the agent failed or committed, or the run failed before any trace |
|
|
66
|
+
| 2 | Usage: an unknown option or a wrong value |
|
|
67
|
+
|
|
68
|
+
Once signed in, a failure is reported to impact.ai with the step it stopped at and a reason that holds no secret, so the
|
|
69
|
+
setup in the browser says what happened. The working tree stays as the agent left it.
|
|
70
|
+
|
|
71
|
+
## What the coding agent may do
|
|
72
|
+
|
|
73
|
+
Each agent runs once, from this folder, as its vendor's documentation describes it (read on 4 December 2026; the flags
|
|
74
|
+
are in [src/agents.js](src/agents.js)):
|
|
75
|
+
|
|
76
|
+
| Agent | Mode | May | May not |
|
|
77
|
+
|---|---|---|---|
|
|
78
|
+
| Claude Code | `claude -p --permission-mode acceptEdits`, the task on stdin | edit files in the folder; run the package installs it is allowed (`npm install`, `pip install`, `uv add` and the like) | any other command (a `-p` run denies what would ask); `git commit`, `git push`, `gh`, reading or changing `.env` (denied outright) |
|
|
79
|
+
| Codex | `codex exec --sandbox workspace-write -c sandbox_workspace_write.network_access=true -`, the task on stdin | write in the folder; reach the network, for package installs | write outside the folder, or to `.git` (so it cannot commit) |
|
|
80
|
+
| Cursor (Grok Build CLI) | `grok -p <task> --permission-mode dontAsk --sandbox workspace` | read, search and edit; the same package installs | anything else (`dontAsk` denies what no rule allows); write outside the folder; `git commit`, `git push`, `gh` |
|
|
81
|
+
|
|
82
|
+
The agent is asked to end its reply with lines the command reads: `IMPACT-RUN:` (the command that runs the application
|
|
83
|
+
once), `IMPACT-SERVICE:` (the service name it set), `IMPACT-ENVIRONMENT:` and one `IMPACT-UNSUPPORTED:` for each library
|
|
84
|
+
or language it could not cover. When it names no run command, the command asks you for one.
|
|
85
|
+
|
|
86
|
+
## When no trace arrives
|
|
87
|
+
|
|
88
|
+
The command says what to check: that the application reads `IMPACT_INGEST_KEY` and `IMPACT_INGEST_ENDPOINT` (from `.env`
|
|
89
|
+
or its environment) when it starts, that it can reach the ingest address from this computer, and that the run makes a
|
|
90
|
+
model call. The setup's page in impact.ai, whose address it prints, keeps following it.
|
|
91
|
+
|
|
92
|
+
## Without the coding agent: the exporter route
|
|
93
|
+
|
|
94
|
+
For a library or language the agent cannot cover, or without an agent, point the application's OpenTelemetry exporter
|
|
95
|
+
at impact.ai yourself, from the two variables in `.env`:
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=<the value of IMPACT_INGEST_ENDPOINT>
|
|
99
|
+
OTEL_EXPORTER_OTLP_TRACES_HEADERS=authorization=Bearer%20<the value of IMPACT_INGEST_KEY>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Develop
|
|
103
|
+
|
|
104
|
+
`make test-setup` runs the tests (`node --test`): a fake impact.ai that speaks the setup protocol, fake coding agents on
|
|
105
|
+
the PATH, and folders of their own. The command is plain JavaScript (ES modules), because Node.js does not strip types
|
|
106
|
+
in `node_modules`; types are in JSDoc. Publishing to npm is a separate, manual step.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// npx @impact-ai/setup: see ../README.md, or run it with --help.
|
|
5
|
+
|
|
6
|
+
import { main } from "../src/main.js";
|
|
7
|
+
|
|
8
|
+
main(process.argv.slice(2)).then(
|
|
9
|
+
(code) => process.exit(code),
|
|
10
|
+
(error) => {
|
|
11
|
+
process.stderr.write(`Failed: ${error?.message ?? error}\n`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
},
|
|
14
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@impact-ai/setup",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Connect the application in this folder to impact.ai: sign in, write one ingest key to .env, let your coding agent add the instrumentation, run the application once and see its first trace checked.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"impact-ai-setup": "bin/impact-ai-setup.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin/",
|
|
12
|
+
"src/",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"NOTICE",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=22"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Impact-AI/impact-ai.git",
|
|
23
|
+
"directory": "setup"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://impact.ai",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "node --test \"test/*.test.js\""
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/agents.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
// The coding agents the command hands its task to, each in its non-interactive mode with the narrowest permissions
|
|
4
|
+
// that let it edit files and install packages in this folder, and the lines the command reads from its reply.
|
|
5
|
+
//
|
|
6
|
+
// Flags as each vendor's documentation gave them on 4 December 2026:
|
|
7
|
+
//
|
|
8
|
+
// Claude Code (`claude`): https://code.claude.com/docs/en/cli-reference, .../headless, .../permission-modes and
|
|
9
|
+
// .../permissions. `-p` runs once and prints the reply; with no prompt argument it reads the prompt from stdin.
|
|
10
|
+
// `--permission-mode acceptEdits` approves file edits inside the working directory; in a `-p` run any other call that
|
|
11
|
+
// would need approval is denied, so `--allowedTools` names the package installs and nothing else, and
|
|
12
|
+
// `--disallowedTools` denies committing, pushing, `gh` and reading or changing .env (deny rules win).
|
|
13
|
+
// Codex (`codex`): https://developers.openai.com/codex/noninteractive, .../codex/cli/reference and
|
|
14
|
+
// .../codex/agent-approvals-security. `codex exec` runs once; `-` reads the prompt from stdin and stdout carries only
|
|
15
|
+
// the final message. `--sandbox workspace-write` lets it write in the working directory only, with the repository's
|
|
16
|
+
// .git read-only (so it cannot commit); `-c sandbox_workspace_write.network_access=true` lets a package install reach
|
|
17
|
+
// the network, which that sandbox turns off by default. `--skip-git-repo-check` only for a folder outside git.
|
|
18
|
+
// Cursor: https://cursor.com/docs/cli now leads to the Grok Build CLI (https://docs.grok.com/build/whats-new,
|
|
19
|
+
// .../build/cli/headless-scripting, .../build/cli/reference, .../build/features/permissions, .../build/features/sandbox,
|
|
20
|
+
// .../build/enterprise): `grok` 2.x runs Cursor's agent harness, and the legacy Cursor CLI (`cursor-agent`) updates to
|
|
21
|
+
// it with `cursor-agent update --channel grok`. `-p <prompt>` runs once, `--output-format plain` prints the reply,
|
|
22
|
+
// `--permission-mode dontAsk` denies whatever no `--allow` rule allows, `--sandbox workspace` limits writes to the
|
|
23
|
+
// working directory (the network stays open for installs), `--deny` wins over `--allow`, and `--no-auto-update` skips
|
|
24
|
+
// the update check in a scripted run. `grok --version` starting with 2 is the new CLI.
|
|
25
|
+
|
|
26
|
+
import { spawnSync } from "node:child_process";
|
|
27
|
+
import { which } from "./processes.js";
|
|
28
|
+
|
|
29
|
+
export const AGENTS = {
|
|
30
|
+
claude: { id: "claude", name: "Claude Code", program: "claude" },
|
|
31
|
+
codex: { id: "codex", name: "Codex", program: "codex" },
|
|
32
|
+
cursor: { id: "cursor", name: "Cursor (the Grok Build CLI)", program: "grok" },
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** Claude Code first when several are installed. */
|
|
36
|
+
export const ORDER = ["claude", "codex", "cursor"];
|
|
37
|
+
|
|
38
|
+
/** The package installs an agent may run: Python's and JavaScript's usual installers. */
|
|
39
|
+
export const INSTALLS = [
|
|
40
|
+
"npm install",
|
|
41
|
+
"npm install *",
|
|
42
|
+
"npm i *",
|
|
43
|
+
"pnpm add *",
|
|
44
|
+
"pnpm install",
|
|
45
|
+
"yarn add *",
|
|
46
|
+
"yarn install",
|
|
47
|
+
"bun add *",
|
|
48
|
+
"pip install *",
|
|
49
|
+
"pip3 install *",
|
|
50
|
+
"python -m pip install *",
|
|
51
|
+
"python3 -m pip install *",
|
|
52
|
+
"uv add *",
|
|
53
|
+
"uv pip install *",
|
|
54
|
+
"uv sync",
|
|
55
|
+
"poetry add *",
|
|
56
|
+
"poetry install",
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
const NEVER = ["git commit *", "git push *", "gh *"];
|
|
60
|
+
|
|
61
|
+
function version(program, env) {
|
|
62
|
+
const cmd = /\.(?:cmd|bat)$/i.test(program);
|
|
63
|
+
const result = spawnSync(cmd ? `"${program}" --version` : program, cmd ? [] : ["--version"], {
|
|
64
|
+
env,
|
|
65
|
+
encoding: "utf8",
|
|
66
|
+
timeout: 15000,
|
|
67
|
+
shell: cmd,
|
|
68
|
+
windowsHide: true,
|
|
69
|
+
});
|
|
70
|
+
const found = /(\d+)\.(\d+)/.exec(`${result.stdout ?? ""}`);
|
|
71
|
+
return found ? Number(found[1]) : null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The agent to use: the one named, or the first installed of Claude Code, Codex and Cursor.
|
|
76
|
+
* @param {string | null} choice
|
|
77
|
+
* @param {Record<string, string | undefined>} env
|
|
78
|
+
* @returns {{ agent: typeof AGENTS.claude, path: string } | { agent: null, notes: string[] }}
|
|
79
|
+
*/
|
|
80
|
+
export function findAgent(choice, env) {
|
|
81
|
+
const notes = [];
|
|
82
|
+
for (const id of choice ? [choice] : ORDER) {
|
|
83
|
+
const agent = AGENTS[id];
|
|
84
|
+
const found = which(agent.program, env);
|
|
85
|
+
if (found && id !== "cursor") return { agent, path: found };
|
|
86
|
+
if (id !== "cursor") continue;
|
|
87
|
+
if (found) {
|
|
88
|
+
const major = version(found, env);
|
|
89
|
+
if (major !== null && major >= 2) return { agent, path: found };
|
|
90
|
+
notes.push(
|
|
91
|
+
"The grok on this computer is the legacy Grok CLI: update it to the Grok Build CLI, which runs Cursor's agent, " +
|
|
92
|
+
"with `grok update --channel unified`.",
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (which("cursor-agent", env)) {
|
|
96
|
+
notes.push(
|
|
97
|
+
"The legacy Cursor CLI (cursor-agent) is installed: update it to the Grok Build CLI, which now runs Cursor's " +
|
|
98
|
+
"agent, with `cursor-agent update --channel grok`.",
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { agent: null, notes };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* How to run the agent once: its arguments, and what goes to its stdin.
|
|
107
|
+
* @param {{ id: string }} agent
|
|
108
|
+
* @param {string} prompt
|
|
109
|
+
* @param {{ inRepository: boolean }} where
|
|
110
|
+
*/
|
|
111
|
+
export function invocation(agent, prompt, { inRepository }) {
|
|
112
|
+
const bash = (command) => `Bash(${command})`;
|
|
113
|
+
if (agent.id === "claude") {
|
|
114
|
+
return {
|
|
115
|
+
args: [
|
|
116
|
+
"-p",
|
|
117
|
+
"--permission-mode",
|
|
118
|
+
"acceptEdits",
|
|
119
|
+
"--output-format",
|
|
120
|
+
"text",
|
|
121
|
+
"--allowedTools",
|
|
122
|
+
...INSTALLS.map(bash),
|
|
123
|
+
"--disallowedTools",
|
|
124
|
+
...NEVER.map(bash),
|
|
125
|
+
"Read(./.env)",
|
|
126
|
+
"Edit(./.env)",
|
|
127
|
+
],
|
|
128
|
+
input: prompt,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (agent.id === "codex") {
|
|
132
|
+
return {
|
|
133
|
+
args: [
|
|
134
|
+
"exec",
|
|
135
|
+
"--sandbox",
|
|
136
|
+
"workspace-write",
|
|
137
|
+
"-c",
|
|
138
|
+
"sandbox_workspace_write.network_access=true",
|
|
139
|
+
...(inRepository ? [] : ["--skip-git-repo-check"]),
|
|
140
|
+
"-",
|
|
141
|
+
],
|
|
142
|
+
input: prompt,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
args: [
|
|
147
|
+
"--no-auto-update",
|
|
148
|
+
"-p",
|
|
149
|
+
prompt,
|
|
150
|
+
"--output-format",
|
|
151
|
+
"plain",
|
|
152
|
+
"--permission-mode",
|
|
153
|
+
"dontAsk",
|
|
154
|
+
"--sandbox",
|
|
155
|
+
"workspace",
|
|
156
|
+
...["Read", "Grep", "Edit", ...INSTALLS.map(bash)].flatMap((rule) => ["--allow", rule]),
|
|
157
|
+
...NEVER.map(bash).flatMap((rule) => ["--deny", rule]),
|
|
158
|
+
],
|
|
159
|
+
input: "",
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The task impact.ai composed, and the command's own request: how to end the reply, and what not to do.
|
|
165
|
+
* @param {string} task
|
|
166
|
+
*/
|
|
167
|
+
export function composePrompt(task) {
|
|
168
|
+
return `${task.trim()}
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
From the impact.ai setup command, which started you and reads your reply:
|
|
172
|
+
- Work only in this folder. Do not commit, push, create a branch or open a pull request: leave every change
|
|
173
|
+
uncommitted for the person to review.
|
|
174
|
+
- IMPACT_INGEST_KEY and IMPACT_INGEST_ENDPOINT are already set in this folder's .env. Do not read, print, copy or
|
|
175
|
+
change .env; the code reads the two variables from its environment.
|
|
176
|
+
- You need not run the application: the setup command runs it once after you finish.
|
|
177
|
+
- End your reply with these lines, each on a line of its own, exactly in this form:
|
|
178
|
+
IMPACT-RUN: <one shell command, run from this folder, that runs the application once>
|
|
179
|
+
IMPACT-SERVICE: <the service name the application reports>
|
|
180
|
+
IMPACT-ENVIRONMENT: <the deployment environment name the application reports>
|
|
181
|
+
IMPACT-UNSUPPORTED: <a library or language you could not instrument; one line for each, and no such line when you covered everything>
|
|
182
|
+
`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const LINE = /^`?(?:\*\*)?IMPACT-(RUN|SERVICE|ENVIRONMENT|UNSUPPORTED)(?:\*\*)?\s*:\s*(.*)$/i;
|
|
186
|
+
const NOTHING = /^(?:none|n\/a|-|nothing|<.*>)$/i;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The machine-readable lines of the agent's reply: the last IMPACT-RUN, IMPACT-SERVICE and IMPACT-ENVIRONMENT, and
|
|
190
|
+
* every IMPACT-UNSUPPORTED that names something.
|
|
191
|
+
* @param {string} reply
|
|
192
|
+
*/
|
|
193
|
+
export function parseReply(reply) {
|
|
194
|
+
const found = { run: null, service: null, environment: null, unsupported: [] };
|
|
195
|
+
for (const raw of reply.split(/\r?\n/)) {
|
|
196
|
+
const line = raw.trim().replace(/^(?:[-*>]\s+)+/, "");
|
|
197
|
+
const match = LINE.exec(line);
|
|
198
|
+
if (!match) continue;
|
|
199
|
+
let value = match[2].trim();
|
|
200
|
+
if (line.startsWith("`") && value.endsWith("`")) value = value.slice(0, -1).trim();
|
|
201
|
+
value = value.replace(/^`([^`]*)`$/, "$1").trim();
|
|
202
|
+
if (!value || NOTHING.test(value)) continue;
|
|
203
|
+
const kind = match[1].toUpperCase();
|
|
204
|
+
if (kind === "UNSUPPORTED") {
|
|
205
|
+
if (!found.unsupported.includes(value)) found.unsupported.push(value.slice(0, 100));
|
|
206
|
+
} else if (kind === "RUN") {
|
|
207
|
+
if (value.length <= 1000) found.run = value;
|
|
208
|
+
} else if (value.length <= 200) {
|
|
209
|
+
found[kind.toLowerCase()] = value;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return found;
|
|
213
|
+
}
|