@sandagent/runner-cli 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 +201 -0
- package/dist/__tests__/runner.test.d.ts +2 -0
- package/dist/__tests__/runner.test.d.ts.map +1 -0
- package/dist/__tests__/runner.test.js +79 -0
- package/dist/__tests__/runner.test.js.map +1 -0
- package/dist/bundle.mjs +544 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +172 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/runner.d.ts +35 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +50 -0
- package/dist/runner.js.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/runner.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
// Mock @sandagent/runner-claude
|
|
3
|
+
vi.mock("@sandagent/runner-claude", () => ({
|
|
4
|
+
createClaudeRunner: vi.fn().mockReturnValue({
|
|
5
|
+
run: vi.fn().mockImplementation(async function* () {
|
|
6
|
+
yield "data: test message\n\n";
|
|
7
|
+
}),
|
|
8
|
+
}),
|
|
9
|
+
}));
|
|
10
|
+
import { createClaudeRunner } from "@sandagent/runner-claude";
|
|
11
|
+
import { runAgent } from "../runner.js";
|
|
12
|
+
describe("runAgent", () => {
|
|
13
|
+
let originalWrite;
|
|
14
|
+
let writtenData;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
writtenData = [];
|
|
17
|
+
originalWrite = process.stdout.write;
|
|
18
|
+
// @ts-ignore - mocking stdout.write
|
|
19
|
+
process.stdout.write = vi.fn((data) => {
|
|
20
|
+
writtenData.push(data);
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
process.stdout.write = originalWrite;
|
|
26
|
+
vi.clearAllMocks();
|
|
27
|
+
});
|
|
28
|
+
it("should create a Claude runner with correct options (with default template)", async () => {
|
|
29
|
+
await runAgent({
|
|
30
|
+
model: "claude-sonnet-4-20250514",
|
|
31
|
+
userInput: "Hello, world!",
|
|
32
|
+
});
|
|
33
|
+
// The runner should be called with template values loaded
|
|
34
|
+
expect(createClaudeRunner).toHaveBeenCalled();
|
|
35
|
+
const callArgs = vi.mocked(createClaudeRunner).mock.calls[0][0];
|
|
36
|
+
expect(callArgs.model).toBe("claude-sonnet-4-20250514");
|
|
37
|
+
// Template provides default allowed tools and maxTurns
|
|
38
|
+
// (or undefined if template not found)
|
|
39
|
+
expect(typeof callArgs.maxTurns === "number" || callArgs.maxTurns === undefined).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it("should pass optional parameters to runner (overriding template)", async () => {
|
|
42
|
+
await runAgent({
|
|
43
|
+
model: "claude-sonnet-4-20250514",
|
|
44
|
+
userInput: "Hello, world!",
|
|
45
|
+
systemPrompt: "You are a helpful assistant",
|
|
46
|
+
maxTurns: 5,
|
|
47
|
+
allowedTools: ["bash", "write_file"],
|
|
48
|
+
});
|
|
49
|
+
// Explicit parameters override template values
|
|
50
|
+
expect(createClaudeRunner).toHaveBeenCalledWith({
|
|
51
|
+
model: "claude-sonnet-4-20250514",
|
|
52
|
+
systemPrompt: "You are a helpful assistant",
|
|
53
|
+
maxTurns: 5,
|
|
54
|
+
allowedTools: ["bash", "write_file"],
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
it("should stream output to stdout without modification", async () => {
|
|
58
|
+
await runAgent({
|
|
59
|
+
model: "claude-sonnet-4-20250514",
|
|
60
|
+
userInput: "Hello, world!",
|
|
61
|
+
});
|
|
62
|
+
expect(process.stdout.write).toHaveBeenCalledWith("data: test message\n\n");
|
|
63
|
+
expect(writtenData).toEqual(["data: test message\n\n"]);
|
|
64
|
+
});
|
|
65
|
+
it("should call runner.run with user input", async () => {
|
|
66
|
+
const mockRunner = {
|
|
67
|
+
run: vi.fn().mockImplementation(async function* () {
|
|
68
|
+
yield "test";
|
|
69
|
+
}),
|
|
70
|
+
};
|
|
71
|
+
vi.mocked(createClaudeRunner).mockReturnValue(mockRunner);
|
|
72
|
+
await runAgent({
|
|
73
|
+
model: "claude-sonnet-4-20250514",
|
|
74
|
+
userInput: "Create a file",
|
|
75
|
+
});
|
|
76
|
+
expect(mockRunner.run).toHaveBeenCalledWith("Create a file", expect.any(AbortSignal));
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=runner.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.test.js","sourceRoot":"","sources":["../../src/__tests__/runner.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEzE,gCAAgC;AAChC,EAAE,CAAC,IAAI,CAAC,0BAA0B,EAAE,GAAG,EAAE,CAAC,CAAC;IACzC,kBAAkB,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC;QAC1C,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,kBAAkB,C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AM,CAAC,kBAAkB,CAAC,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;QAE1D,MAAM,QAAQ,CAAC;YACb,KAAK,EAAE,0BAA0B;YACjC,SAAS,EAAE,eAAe;SAC3B,CAAC,CAAC;QAEH,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,oBAAoB,CACzC,eAAe,EACf,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CACxB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/bundle.mjs
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
|
|
6
|
+
// ../../packages/runner-claude/dist/claude-runner.js
|
|
7
|
+
var SettingSource;
|
|
8
|
+
(function(SettingSource2) {
|
|
9
|
+
SettingSource2["user"] = "user";
|
|
10
|
+
SettingSource2["project"] = "project";
|
|
11
|
+
})(SettingSource || (SettingSource = {}));
|
|
12
|
+
function createCanUseToolCallback(claudeOptions) {
|
|
13
|
+
return async (toolName, input, options) => {
|
|
14
|
+
const { toolUseID } = options;
|
|
15
|
+
if (toolName !== "AskUserQuestion") {
|
|
16
|
+
return {
|
|
17
|
+
behavior: "allow",
|
|
18
|
+
updatedInput: input
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const approvalDir = claudeOptions.approvalDir;
|
|
22
|
+
if (!approvalDir) {
|
|
23
|
+
return { behavior: "deny", message: "User not answer" };
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const { execSync } = await import("node:child_process");
|
|
27
|
+
const path = await import("node:path");
|
|
28
|
+
const approvalFile = path.join(approvalDir, `${toolUseID}.json`);
|
|
29
|
+
const timeout = Date.now() + 6e4;
|
|
30
|
+
let lastApproval = null;
|
|
31
|
+
while (Date.now() < timeout) {
|
|
32
|
+
try {
|
|
33
|
+
const data = execSync(`cat ${approvalFile} 2>/dev/null`, {
|
|
34
|
+
encoding: "utf-8"
|
|
35
|
+
});
|
|
36
|
+
const approval = JSON.parse(data);
|
|
37
|
+
lastApproval = approval;
|
|
38
|
+
if (approval.status === "completed") {
|
|
39
|
+
try {
|
|
40
|
+
execSync(`rm ${approvalFile} 2>/dev/null`);
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
behavior: "allow",
|
|
45
|
+
updatedInput: {
|
|
46
|
+
questions: approval.questions,
|
|
47
|
+
answers: approval.answers
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
}
|
|
53
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
execSync(`rm ${approvalFile} 2>/dev/null`);
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
if (lastApproval && Object.keys(lastApproval.answers).length > 0) {
|
|
60
|
+
return {
|
|
61
|
+
behavior: "allow",
|
|
62
|
+
updatedInput: {
|
|
63
|
+
questions: lastApproval.questions,
|
|
64
|
+
answers: lastApproval.answers
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
behavior: "deny",
|
|
70
|
+
message: "Timeout waiting for user input"
|
|
71
|
+
};
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error("Failed to handle approval flow:", error);
|
|
74
|
+
return {
|
|
75
|
+
behavior: "deny",
|
|
76
|
+
message: "Failed to handle approval flow"
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
var OPTIONAL_MODULES = {
|
|
82
|
+
"claude-agent-sdk": "@anthropic-ai/claude-agent-sdk"
|
|
83
|
+
};
|
|
84
|
+
function createClaudeRunner(options) {
|
|
85
|
+
return {
|
|
86
|
+
async *run(userInput, signal) {
|
|
87
|
+
if (signal?.aborted) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const apiKey = process.env.ANTHROPIC_API_KEY || process.env.AWS_BEARER_TOKEN_BEDROCK;
|
|
91
|
+
if (!apiKey) {
|
|
92
|
+
console.error("[SandAgent] Warning: ANTHROPIC_API_KEY or AWS_BEARER_TOKEN_BEDROCK not set. Using mock response.\nTo use the real Claude Agent SDK:\n1. Set ANTHROPIC_API_KEY or AWS_BEARER_TOKEN_BEDROCK environment variable\n2. Install the SDK: npm install @anthropic-ai/claude-agent-sdk");
|
|
93
|
+
yield* runMockAgent(options, userInput, signal);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const sdk = await loadClaudeAgentSDK();
|
|
97
|
+
if (sdk) {
|
|
98
|
+
yield* runWithClaudeAgentSDK(sdk, options, userInput, signal);
|
|
99
|
+
} else {
|
|
100
|
+
console.error("[SandAgent] Warning: @anthropic-ai/claude-agent-sdk not installed. Using mock response.\nInstall the SDK: npm install @anthropic-ai/claude-agent-sdk");
|
|
101
|
+
yield* runMockAgent(options, userInput, signal);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async function loadClaudeAgentSDK() {
|
|
107
|
+
try {
|
|
108
|
+
const modulePath = OPTIONAL_MODULES["claude-agent-sdk"];
|
|
109
|
+
const module = await import(
|
|
110
|
+
/* webpackIgnore: true */
|
|
111
|
+
modulePath
|
|
112
|
+
);
|
|
113
|
+
return module;
|
|
114
|
+
} catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async function* runWithClaudeAgentSDK(sdk, options, userInput, signal) {
|
|
119
|
+
const usage = { inputTokens: 0, outputTokens: 0 };
|
|
120
|
+
let systemMessage;
|
|
121
|
+
let messageId;
|
|
122
|
+
const sdkOptions = {
|
|
123
|
+
model: options.model,
|
|
124
|
+
systemPrompt: options.systemPrompt,
|
|
125
|
+
maxTurns: options.maxTurns,
|
|
126
|
+
allowedTools: [...options.allowedTools ?? [], "Skill"],
|
|
127
|
+
cwd: options.cwd,
|
|
128
|
+
env: options.env,
|
|
129
|
+
resume: options.resume,
|
|
130
|
+
settingSources: [SettingSource.project, SettingSource.user],
|
|
131
|
+
canUseTool: createCanUseToolCallback(options),
|
|
132
|
+
// Bypass all permission checks for automated execution
|
|
133
|
+
permissionMode: "bypassPermissions",
|
|
134
|
+
allowDangerouslySkipPermissions: true
|
|
135
|
+
};
|
|
136
|
+
const queryIterator = sdk.query({
|
|
137
|
+
prompt: userInput,
|
|
138
|
+
options: sdkOptions
|
|
139
|
+
});
|
|
140
|
+
const abortHandler = async () => {
|
|
141
|
+
console.error("[ClaudeRunner] Operation aborted, calling query.interrupt()");
|
|
142
|
+
await queryIterator.interrupt();
|
|
143
|
+
};
|
|
144
|
+
if (signal) {
|
|
145
|
+
console.error("[ClaudeRunner] Signal provided, adding abort listener");
|
|
146
|
+
signal.addEventListener("abort", abortHandler);
|
|
147
|
+
if (signal.aborted) {
|
|
148
|
+
console.error("[ClaudeRunner] Signal already aborted!");
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
console.error("[ClaudeRunner] No signal provided");
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
for await (const message of queryIterator) {
|
|
155
|
+
if (message.type === "system" && message.subtype === "init") {
|
|
156
|
+
systemMessage = message;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (message.type === "assistant" && !messageId && systemMessage) {
|
|
160
|
+
messageId = message.message.id;
|
|
161
|
+
yield formatDataStream({
|
|
162
|
+
type: "start",
|
|
163
|
+
messageId
|
|
164
|
+
});
|
|
165
|
+
yield formatDataStream({
|
|
166
|
+
type: "message-metadata",
|
|
167
|
+
messageMetadata: {
|
|
168
|
+
tools: systemMessage.tools,
|
|
169
|
+
model: systemMessage.model,
|
|
170
|
+
sessionId: systemMessage.session_id
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const chunks = convertSDKMessageToAISDKUI(message);
|
|
175
|
+
for (const chunk of chunks) {
|
|
176
|
+
yield chunk;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} catch (error) {
|
|
180
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
181
|
+
console.error("[ClaudeRunner] Error:", errorMessage);
|
|
182
|
+
yield formatDataStream({ type: "error", errorText: errorMessage });
|
|
183
|
+
yield formatDataStream({
|
|
184
|
+
type: "finish",
|
|
185
|
+
finishReason: "error",
|
|
186
|
+
usage: {
|
|
187
|
+
promptTokens: usage.inputTokens,
|
|
188
|
+
completionTokens: usage.outputTokens
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
} finally {
|
|
192
|
+
if (signal) {
|
|
193
|
+
signal.removeEventListener("abort", abortHandler);
|
|
194
|
+
}
|
|
195
|
+
yield `data: [DONE]
|
|
196
|
+
|
|
197
|
+
`;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function convertSDKMessageToAISDKUI(message) {
|
|
201
|
+
const chunks = [];
|
|
202
|
+
switch (message.type) {
|
|
203
|
+
case "assistant": {
|
|
204
|
+
const assistantMsg = message;
|
|
205
|
+
if (assistantMsg.error) {
|
|
206
|
+
const errorDetail = message.message.content.map((c) => c.text).join("\n");
|
|
207
|
+
chunks.push(formatDataStream({
|
|
208
|
+
type: "error",
|
|
209
|
+
errorText: `${assistantMsg.error}: ${errorDetail}`
|
|
210
|
+
}));
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
if (assistantMsg.message) {
|
|
214
|
+
if (typeof assistantMsg.message === "string") {
|
|
215
|
+
const textId = generateId();
|
|
216
|
+
chunks.push(formatDataStream({ type: "text-start", id: textId }));
|
|
217
|
+
chunks.push(formatDataStream({
|
|
218
|
+
type: "text-delta",
|
|
219
|
+
id: textId,
|
|
220
|
+
delta: assistantMsg.message
|
|
221
|
+
}));
|
|
222
|
+
chunks.push(formatDataStream({ type: "text-end", id: textId }));
|
|
223
|
+
} else if (assistantMsg.message.content && Array.isArray(assistantMsg.message.content)) {
|
|
224
|
+
for (const block of assistantMsg.message.content) {
|
|
225
|
+
if (block.type === "text" && block.text) {
|
|
226
|
+
const textId = generateId();
|
|
227
|
+
chunks.push(formatDataStream({ type: "text-start", id: textId }));
|
|
228
|
+
chunks.push(formatDataStream({
|
|
229
|
+
type: "text-delta",
|
|
230
|
+
id: textId,
|
|
231
|
+
delta: block.text
|
|
232
|
+
}));
|
|
233
|
+
chunks.push(formatDataStream({ type: "text-end", id: textId }));
|
|
234
|
+
} else if (block.type === "tool_use") {
|
|
235
|
+
const toolCallId = block.id || generateId();
|
|
236
|
+
chunks.push(formatDataStream({
|
|
237
|
+
type: "tool-input-start",
|
|
238
|
+
toolCallId,
|
|
239
|
+
toolName: block.name,
|
|
240
|
+
dynamic: true
|
|
241
|
+
}));
|
|
242
|
+
if (block.input) {
|
|
243
|
+
chunks.push(formatDataStream({
|
|
244
|
+
type: "tool-input-available",
|
|
245
|
+
toolCallId,
|
|
246
|
+
toolName: block.name,
|
|
247
|
+
dynamic: true,
|
|
248
|
+
input: block.input
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
case "result": {
|
|
258
|
+
const resultMsg = message;
|
|
259
|
+
chunks.push(formatDataStream({
|
|
260
|
+
type: "finish",
|
|
261
|
+
finishReason: resultMsg.is_error ? "error" : "stop",
|
|
262
|
+
messageMetadata: {
|
|
263
|
+
usage: resultMsg.usage,
|
|
264
|
+
duration_ms: resultMsg.duration_ms,
|
|
265
|
+
num_turns: resultMsg.num_turns,
|
|
266
|
+
total_cost_usd: resultMsg.total_cost_usd
|
|
267
|
+
}
|
|
268
|
+
}));
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
case "user": {
|
|
272
|
+
const usrMsg = message;
|
|
273
|
+
if (usrMsg.isSynthetic) {
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
const contentArray = usrMsg.message.content;
|
|
277
|
+
if (usrMsg.tool_use_result || Array.isArray(contentArray) && contentArray.some((c) => c.type === "tool_result")) {
|
|
278
|
+
for (const tool of contentArray) {
|
|
279
|
+
if (tool.is_error) {
|
|
280
|
+
chunks.push(formatDataStream({
|
|
281
|
+
type: "tool-output-error",
|
|
282
|
+
toolCallId: tool.tool_use_id,
|
|
283
|
+
errorText: tool.content,
|
|
284
|
+
dynamic: true
|
|
285
|
+
}));
|
|
286
|
+
} else {
|
|
287
|
+
chunks.push(formatDataStream({
|
|
288
|
+
type: "tool-output-available",
|
|
289
|
+
toolCallId: tool.tool_use_id,
|
|
290
|
+
output: usrMsg.tool_use_result || tool.content,
|
|
291
|
+
dynamic: true
|
|
292
|
+
}));
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
default:
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
return chunks;
|
|
302
|
+
}
|
|
303
|
+
function formatDataStream(data) {
|
|
304
|
+
return `data: ${JSON.stringify(data)}
|
|
305
|
+
|
|
306
|
+
`;
|
|
307
|
+
}
|
|
308
|
+
function generateId() {
|
|
309
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
310
|
+
}
|
|
311
|
+
async function* runMockAgent(options, userInput, signal) {
|
|
312
|
+
if (signal?.aborted) {
|
|
313
|
+
console.log("[ClaudeRunner] Mock agent: Operation already aborted");
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
try {
|
|
317
|
+
const response = `I received your request: "${userInput}"
|
|
318
|
+
|
|
319
|
+
Model: ${options.model}
|
|
320
|
+
|
|
321
|
+
This is a mock response because:
|
|
322
|
+
- ANTHROPIC_API_KEY is not set, OR
|
|
323
|
+
- @anthropic-ai/claude-agent-sdk is not installed
|
|
324
|
+
|
|
325
|
+
To use the real Claude Agent SDK:
|
|
326
|
+
1. Set ANTHROPIC_API_KEY environment variable
|
|
327
|
+
2. Install the SDK: npm install @anthropic-ai/claude-agent-sdk
|
|
328
|
+
|
|
329
|
+
Documentation: https://platform.claude.com/docs/en/agent-sdk/typescript-v2-preview`;
|
|
330
|
+
const textId = generateId();
|
|
331
|
+
yield formatDataStream({ type: "text-start", id: textId });
|
|
332
|
+
const words = response.split(" ");
|
|
333
|
+
for (const word of words) {
|
|
334
|
+
yield formatDataStream({
|
|
335
|
+
type: "text-delta",
|
|
336
|
+
id: textId,
|
|
337
|
+
delta: word + " "
|
|
338
|
+
});
|
|
339
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
340
|
+
}
|
|
341
|
+
yield formatDataStream({ type: "text-end", id: textId });
|
|
342
|
+
yield formatDataStream({
|
|
343
|
+
type: "finish",
|
|
344
|
+
finishReason: "stop"
|
|
345
|
+
});
|
|
346
|
+
yield `data: [DONE]
|
|
347
|
+
|
|
348
|
+
`;
|
|
349
|
+
} catch (error) {
|
|
350
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
351
|
+
console.error("[ClaudeRunner] Mock agent error:", errorMessage);
|
|
352
|
+
yield formatDataStream({ type: "error", errorText: errorMessage });
|
|
353
|
+
yield formatDataStream({
|
|
354
|
+
type: "finish",
|
|
355
|
+
finishReason: "error"
|
|
356
|
+
});
|
|
357
|
+
yield `data: [DONE]
|
|
358
|
+
|
|
359
|
+
`;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/runner.ts
|
|
364
|
+
async function runAgent(options) {
|
|
365
|
+
const abortController = new AbortController();
|
|
366
|
+
const signalHandler = () => {
|
|
367
|
+
console.error("[Runner] Received termination signal, stopping...");
|
|
368
|
+
abortController.abort();
|
|
369
|
+
console.error("[Runner] AbortController.abort() called");
|
|
370
|
+
};
|
|
371
|
+
process.on("SIGTERM", signalHandler);
|
|
372
|
+
process.on("SIGINT", signalHandler);
|
|
373
|
+
console.error("[Runner] Signal handlers registered");
|
|
374
|
+
try {
|
|
375
|
+
const runnerOptions = {
|
|
376
|
+
model: options.model,
|
|
377
|
+
systemPrompt: options.systemPrompt,
|
|
378
|
+
maxTurns: options.maxTurns,
|
|
379
|
+
allowedTools: options.allowedTools,
|
|
380
|
+
resume: options.resume,
|
|
381
|
+
approvalDir: options.approvalDir
|
|
382
|
+
};
|
|
383
|
+
const runner = createClaudeRunner(runnerOptions);
|
|
384
|
+
for await (const chunk of runner.run(
|
|
385
|
+
options.userInput,
|
|
386
|
+
abortController.signal
|
|
387
|
+
)) {
|
|
388
|
+
process.stdout.write(chunk);
|
|
389
|
+
}
|
|
390
|
+
} finally {
|
|
391
|
+
process.off("SIGTERM", signalHandler);
|
|
392
|
+
process.off("SIGINT", signalHandler);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// src/cli.ts
|
|
397
|
+
function parseCliArgs() {
|
|
398
|
+
const { values, positionals } = parseArgs({
|
|
399
|
+
options: {
|
|
400
|
+
model: {
|
|
401
|
+
type: "string",
|
|
402
|
+
short: "m",
|
|
403
|
+
default: "claude-sonnet-4-20250514"
|
|
404
|
+
},
|
|
405
|
+
cwd: {
|
|
406
|
+
type: "string",
|
|
407
|
+
short: "c",
|
|
408
|
+
default: process.env.SANDAGENT_WORKSPACE ?? process.cwd()
|
|
409
|
+
},
|
|
410
|
+
template: {
|
|
411
|
+
type: "string",
|
|
412
|
+
short: "T",
|
|
413
|
+
default: process.env.SANDAGENT_TEMPLATE ?? "default"
|
|
414
|
+
},
|
|
415
|
+
"system-prompt": {
|
|
416
|
+
type: "string",
|
|
417
|
+
short: "s"
|
|
418
|
+
},
|
|
419
|
+
"max-turns": {
|
|
420
|
+
type: "string",
|
|
421
|
+
short: "t"
|
|
422
|
+
},
|
|
423
|
+
"allowed-tools": {
|
|
424
|
+
type: "string",
|
|
425
|
+
short: "a"
|
|
426
|
+
},
|
|
427
|
+
resume: {
|
|
428
|
+
type: "string",
|
|
429
|
+
short: "r"
|
|
430
|
+
},
|
|
431
|
+
"approval-dir": {
|
|
432
|
+
type: "string"
|
|
433
|
+
},
|
|
434
|
+
help: {
|
|
435
|
+
type: "boolean",
|
|
436
|
+
short: "h"
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
allowPositionals: true,
|
|
440
|
+
strict: true
|
|
441
|
+
});
|
|
442
|
+
if (values.help) {
|
|
443
|
+
printHelp();
|
|
444
|
+
process.exit(0);
|
|
445
|
+
}
|
|
446
|
+
if (positionals[0] !== "run") {
|
|
447
|
+
console.error('Error: Expected "run" command');
|
|
448
|
+
console.error('Usage: sandagent run [options] -- "<user input>"');
|
|
449
|
+
process.exit(1);
|
|
450
|
+
}
|
|
451
|
+
const dashIndex = process.argv.indexOf("--");
|
|
452
|
+
let userInput = "";
|
|
453
|
+
if (dashIndex !== -1 && dashIndex < process.argv.length - 1) {
|
|
454
|
+
userInput = process.argv.slice(dashIndex + 1).join(" ");
|
|
455
|
+
} else if (positionals.length > 1) {
|
|
456
|
+
userInput = positionals.slice(1).join(" ");
|
|
457
|
+
}
|
|
458
|
+
if (!userInput) {
|
|
459
|
+
console.error("Error: User input is required");
|
|
460
|
+
console.error('Usage: sandagent run [options] -- "<user input>"');
|
|
461
|
+
process.exit(1);
|
|
462
|
+
}
|
|
463
|
+
return {
|
|
464
|
+
model: values.model,
|
|
465
|
+
cwd: values.cwd,
|
|
466
|
+
template: values.template,
|
|
467
|
+
systemPrompt: values["system-prompt"],
|
|
468
|
+
maxTurns: values["max-turns"] ? Number.parseInt(values["max-turns"], 10) : void 0,
|
|
469
|
+
allowedTools: values["allowed-tools"]?.split(",").map((t) => t.trim()),
|
|
470
|
+
resume: values.resume,
|
|
471
|
+
approvalDir: values["approval-dir"],
|
|
472
|
+
userInput
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
function printHelp() {
|
|
476
|
+
console.log(`
|
|
477
|
+
\u{1F916} SandAgent Runner CLI
|
|
478
|
+
|
|
479
|
+
Like gemini-cli or claude-code - runs locally in your terminal.
|
|
480
|
+
Streams AI SDK UI messages directly to stdout.
|
|
481
|
+
|
|
482
|
+
Usage:
|
|
483
|
+
sandagent run [options] -- "<user input>"
|
|
484
|
+
|
|
485
|
+
# Or run from a template directory:
|
|
486
|
+
cd templates/coder
|
|
487
|
+
sandagent run -- "Build a REST API"
|
|
488
|
+
|
|
489
|
+
Options:
|
|
490
|
+
-m, --model <model> Model to use (default: claude-sonnet-4-20250514)
|
|
491
|
+
-c, --cwd <path> Working directory (default: current directory)
|
|
492
|
+
-T, --template <name> Template to use (default: default)
|
|
493
|
+
Available: default, coder, analyst, researcher
|
|
494
|
+
-s, --system-prompt <prompt> Custom system prompt (overrides template)
|
|
495
|
+
-t, --max-turns <n> Maximum conversation turns
|
|
496
|
+
-a, --allowed-tools <tools> Comma-separated list of allowed tools
|
|
497
|
+
-r, --resume <session-id> Resume a previous session
|
|
498
|
+
-h, --help Show this help message
|
|
499
|
+
|
|
500
|
+
Environment Variables:
|
|
501
|
+
ANTHROPIC_API_KEY Anthropic API key (required)
|
|
502
|
+
SANDAGENT_WORKSPACE Default workspace path
|
|
503
|
+
SANDAGENT_TEMPLATE Default template to use
|
|
504
|
+
SANDAGENT_LOG_LEVEL Logging level (debug, info, warn, error)
|
|
505
|
+
|
|
506
|
+
Templates:
|
|
507
|
+
default General-purpose assistant
|
|
508
|
+
coder Optimized for software development
|
|
509
|
+
analyst Optimized for data analysis
|
|
510
|
+
researcher Optimized for research tasks
|
|
511
|
+
|
|
512
|
+
Examples:
|
|
513
|
+
# Run with default template
|
|
514
|
+
sandagent run -- "Create a hello world script"
|
|
515
|
+
|
|
516
|
+
# Run from a template directory (recommended)
|
|
517
|
+
cd templates/coder
|
|
518
|
+
sandagent run -- "Build a REST API with Express"
|
|
519
|
+
|
|
520
|
+
# Use a specific template
|
|
521
|
+
sandagent run --template analyst -- "Analyze sales.csv"
|
|
522
|
+
|
|
523
|
+
# Specify working directory
|
|
524
|
+
sandagent run --cwd ./my-project -- "Fix the bug in main.ts"
|
|
525
|
+
`);
|
|
526
|
+
}
|
|
527
|
+
async function main() {
|
|
528
|
+
const args = parseCliArgs();
|
|
529
|
+
process.chdir(args.cwd);
|
|
530
|
+
await runAgent({
|
|
531
|
+
model: args.model,
|
|
532
|
+
template: args.template,
|
|
533
|
+
userInput: args.userInput,
|
|
534
|
+
systemPrompt: args.systemPrompt,
|
|
535
|
+
maxTurns: args.maxTurns,
|
|
536
|
+
allowedTools: args.allowedTools,
|
|
537
|
+
resume: args.resume,
|
|
538
|
+
approvalDir: args.approvalDir
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
main().catch((error) => {
|
|
542
|
+
console.error("Fatal error:", error.message);
|
|
543
|
+
process.exit(1);
|
|
544
|
+
});
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* SandAgent Runner CLI
|
|
4
|
+
*
|
|
5
|
+
* Like gemini-cli or claude-code - runs locally in your terminal.
|
|
6
|
+
* Streams AI SDK UI messages directly to stdout.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* sandagent run [options] -- "<user input>"
|
|
10
|
+
*
|
|
11
|
+
* The CLI is designed to be executed in a specific working directory
|
|
12
|
+
* (e.g., a template directory) and outputs AI SDK UI messages directly.
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;GAWG"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* SandAgent Runner CLI
|
|
4
|
+
*
|
|
5
|
+
* Like gemini-cli or claude-code - runs locally in your terminal.
|
|
6
|
+
* Streams AI SDK UI messages directly to stdout.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* sandagent run [options] -- "<user input>"
|
|
10
|
+
*
|
|
11
|
+
* The CLI is designed to be executed in a specific working directory
|
|
12
|
+
* (e.g., a template directory) and outputs AI SDK UI messages directly.
|
|
13
|
+
*/
|
|
14
|
+
import { parseArgs } from "node:util";
|
|
15
|
+
import { runAgent } from "./runner.js";
|
|
16
|
+
function parseCliArgs() {
|
|
17
|
+
const { values, positionals } = parseArgs({
|
|
18
|
+
options: {
|
|
19
|
+
model: {
|
|
20
|
+
type: "string",
|
|
21
|
+
short: "m",
|
|
22
|
+
default: "claude-sonnet-4-20250514",
|
|
23
|
+
},
|
|
24
|
+
cwd: {
|
|
25
|
+
type: "string",
|
|
26
|
+
short: "c",
|
|
27
|
+
default: process.env.SANDAGENT_WORKSPACE ?? process.cwd(),
|
|
28
|
+
},
|
|
29
|
+
template: {
|
|
30
|
+
type: "string",
|
|
31
|
+
short: "T",
|
|
32
|
+
default: process.env.SANDAGENT_TEMPLATE ?? "default",
|
|
33
|
+
},
|
|
34
|
+
"system-prompt": {
|
|
35
|
+
type: "string",
|
|
36
|
+
short: "s",
|
|
37
|
+
},
|
|
38
|
+
"max-turns": {
|
|
39
|
+
type: "string",
|
|
40
|
+
short: "t",
|
|
41
|
+
},
|
|
42
|
+
"allowed-tools": {
|
|
43
|
+
type: "string",
|
|
44
|
+
short: "a",
|
|
45
|
+
},
|
|
46
|
+
resume: {
|
|
47
|
+
type: "string",
|
|
48
|
+
short: "r",
|
|
49
|
+
},
|
|
50
|
+
"approval-dir": {
|
|
51
|
+
type: "string",
|
|
52
|
+
},
|
|
53
|
+
help: {
|
|
54
|
+
type: "boolean",
|
|
55
|
+
short: "h",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
allowPositionals: true,
|
|
59
|
+
strict: true,
|
|
60
|
+
});
|
|
61
|
+
if (values.help) {
|
|
62
|
+
printHelp();
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
// Check for "run" command
|
|
66
|
+
if (positionals[0] !== "run") {
|
|
67
|
+
console.error('Error: Expected "run" command');
|
|
68
|
+
console.error('Usage: sandagent run [options] -- "<user input>"');
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
// Get user input from positionals after "--"
|
|
72
|
+
const dashIndex = process.argv.indexOf("--");
|
|
73
|
+
let userInput = "";
|
|
74
|
+
if (dashIndex !== -1 && dashIndex < process.argv.length - 1) {
|
|
75
|
+
userInput = process.argv.slice(dashIndex + 1).join(" ");
|
|
76
|
+
}
|
|
77
|
+
else if (positionals.length > 1) {
|
|
78
|
+
userInput = positionals.slice(1).join(" ");
|
|
79
|
+
}
|
|
80
|
+
if (!userInput) {
|
|
81
|
+
console.error("Error: User input is required");
|
|
82
|
+
console.error('Usage: sandagent run [options] -- "<user input>"');
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
model: values.model,
|
|
87
|
+
cwd: values.cwd,
|
|
88
|
+
template: values.template,
|
|
89
|
+
systemPrompt: values["system-prompt"],
|
|
90
|
+
maxTurns: values["max-turns"]
|
|
91
|
+
? Number.parseInt(values["max-turns"], 10)
|
|
92
|
+
: undefined,
|
|
93
|
+
allowedTools: values["allowed-tools"]?.split(",").map((t) => t.trim()),
|
|
94
|
+
resume: values.resume,
|
|
95
|
+
approvalDir: values["approval-dir"],
|
|
96
|
+
userInput,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function printHelp() {
|
|
100
|
+
console.log(`
|
|
101
|
+
🤖 SandAgent Runner CLI
|
|
102
|
+
|
|
103
|
+
Like gemini-cli or claude-code - runs locally in your terminal.
|
|
104
|
+
Streams AI SDK UI messages directly to stdout.
|
|
105
|
+
|
|
106
|
+
Usage:
|
|
107
|
+
sandagent run [options] -- "<user input>"
|
|
108
|
+
|
|
109
|
+
# Or run from a template directory:
|
|
110
|
+
cd templates/coder
|
|
111
|
+
sandagent run -- "Build a REST API"
|
|
112
|
+
|
|
113
|
+
Options:
|
|
114
|
+
-m, --model <model> Model to use (default: claude-sonnet-4-20250514)
|
|
115
|
+
-c, --cwd <path> Working directory (default: current directory)
|
|
116
|
+
-T, --template <name> Template to use (default: default)
|
|
117
|
+
Available: default, coder, analyst, researcher
|
|
118
|
+
-s, --system-prompt <prompt> Custom system prompt (overrides template)
|
|
119
|
+
-t, --max-turns <n> Maximum conversation turns
|
|
120
|
+
-a, --allowed-tools <tools> Comma-separated list of allowed tools
|
|
121
|
+
-r, --resume <session-id> Resume a previous session
|
|
122
|
+
-h, --help Show this help message
|
|
123
|
+
|
|
124
|
+
Environment Variables:
|
|
125
|
+
ANTHROPIC_API_KEY Anthropic API key (required)
|
|
126
|
+
SANDAGENT_WORKSPACE Default workspace path
|
|
127
|
+
SANDAGENT_TEMPLATE Default template to use
|
|
128
|
+
SANDAGENT_LOG_LEVEL Logging level (debug, info, warn, error)
|
|
129
|
+
|
|
130
|
+
Templates:
|
|
131
|
+
default General-purpose assistant
|
|
132
|
+
coder Optimized for software development
|
|
133
|
+
analyst Optimized for data analysis
|
|
134
|
+
researcher Optimized for research tasks
|
|
135
|
+
|
|
136
|
+
Examples:
|
|
137
|
+
# Run with default template
|
|
138
|
+
sandagent run -- "Create a hello world script"
|
|
139
|
+
|
|
140
|
+
# Run from a template directory (recommended)
|
|
141
|
+
cd templates/coder
|
|
142
|
+
sandagent run -- "Build a REST API with Express"
|
|
143
|
+
|
|
144
|
+
# Use a specific template
|
|
145
|
+
sandagent run --template analyst -- "Analyze sales.csv"
|
|
146
|
+
|
|
147
|
+
# Specify working directory
|
|
148
|
+
sandagent run --cwd ./my-project -- "Fix the bug in main.ts"
|
|
149
|
+
`);
|
|
150
|
+
}
|
|
151
|
+
async function main() {
|
|
152
|
+
const args = parseCliArgs();
|
|
153
|
+
// Change to the specified working directory
|
|
154
|
+
process.chdir(args.cwd);
|
|
155
|
+
// Run the agent and stream output to stdout
|
|
156
|
+
await runAgent({
|
|
157
|
+
model: args.model,
|
|
158
|
+
template: args.template,
|
|
159
|
+
userInput: args.userInput,
|
|
160
|
+
systemPrompt: args.systemPrompt,
|
|
161
|
+
maxTurns: args.maxTurns,
|
|
162
|
+
allowedTools: args.allowedTools,
|
|
163
|
+
resume: args.resume,
|
|
164
|
+
approvalDir: args.approvalDir,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
main().catch((error) => {
|
|
168
|
+
// Errors go to stderr, not stdout
|
|
169
|
+
console.error("Fatal error:", error.message);
|
|
170
|
+
process.exit(1);
|
|
171
|
+
});
|
|
172
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAcvC,SAAS,YAAY;IACnB,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;QACxC,OAAO,EAAE;YACP,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,GAAG;gBACV,OAAO,EAAE,0BAA0B;aACpC;YACD,GAAG,EAAE;gBACH,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,GAAG;gBACV,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE;aAC1D;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,GAAG;gBACV,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,SAAS;aACrD;YACD,eAAe,EAAE;gBACf,IAAI,EAAE,QAAQ;gBACd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IAAI,CAAC,QAAQ;QACvB,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,WAAW,EAAE,IAAI,CAAC,WAAW;KAC9B,CAAC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,kCAAkC;IAClC,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAwB,MAAM,aAAa,CAAC"}
|
package/dist/runner.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for running the agent
|
|
3
|
+
*/
|
|
4
|
+
export interface RunAgentOptions {
|
|
5
|
+
/** Model to use */
|
|
6
|
+
model: string;
|
|
7
|
+
/** User input/task */
|
|
8
|
+
userInput: string;
|
|
9
|
+
/** Template to use (e.g., "default", "coder", "analyst", "researcher") */
|
|
10
|
+
template?: string;
|
|
11
|
+
/** Custom system prompt (overrides template) */
|
|
12
|
+
systemPrompt?: string;
|
|
13
|
+
/** Maximum conversation turns */
|
|
14
|
+
maxTurns?: number;
|
|
15
|
+
/** Allowed tools */
|
|
16
|
+
allowedTools?: string[];
|
|
17
|
+
/** Resume session ID for multi-turn conversation */
|
|
18
|
+
resume?: string;
|
|
19
|
+
/** Approval file directory for tool approval flow (e.g., "/sandagent/approvals") */
|
|
20
|
+
approvalDir?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Run the agent and stream AI SDK UI messages to stdout.
|
|
24
|
+
*
|
|
25
|
+
* This function:
|
|
26
|
+
* 1. Uses process.cwd() as project directory (set by cli.ts via --cwd)
|
|
27
|
+
* 2. Creates a Claude runner with settingSources: ["project"]
|
|
28
|
+
* 3. SDK automatically loads CLAUDE.md, .claude/settings.json, .claude/skills/*.skill.md
|
|
29
|
+
* 4. Streams messages directly to stdout
|
|
30
|
+
* 5. Handles SIGTERM/SIGINT signals to gracefully stop the runner
|
|
31
|
+
*
|
|
32
|
+
* The output is a valid AI SDK UI stream.
|
|
33
|
+
*/
|
|
34
|
+
export declare function runAgent(options: RunAgentOptions): Promise<void>;
|
|
35
|
+
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,mBAAmB;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB;IACpB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oFAAoF;IACpF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CA2CtE"}
|
package/dist/runner.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createClaudeRunner, } from "@sandagent/runner-claude";
|
|
2
|
+
/**
|
|
3
|
+
* Run the agent and stream AI SDK UI messages to stdout.
|
|
4
|
+
*
|
|
5
|
+
* This function:
|
|
6
|
+
* 1. Uses process.cwd() as project directory (set by cli.ts via --cwd)
|
|
7
|
+
* 2. Creates a Claude runner with settingSources: ["project"]
|
|
8
|
+
* 3. SDK automatically loads CLAUDE.md, .claude/settings.json, .claude/skills/*.skill.md
|
|
9
|
+
* 4. Streams messages directly to stdout
|
|
10
|
+
* 5. Handles SIGTERM/SIGINT signals to gracefully stop the runner
|
|
11
|
+
*
|
|
12
|
+
* The output is a valid AI SDK UI stream.
|
|
13
|
+
*/
|
|
14
|
+
export async function runAgent(options) {
|
|
15
|
+
// Create an AbortController to handle process signals
|
|
16
|
+
const abortController = new AbortController();
|
|
17
|
+
// Handle SIGTERM and SIGINT signals
|
|
18
|
+
const signalHandler = () => {
|
|
19
|
+
console.error("[Runner] Received termination signal, stopping...");
|
|
20
|
+
abortController.abort();
|
|
21
|
+
console.error("[Runner] AbortController.abort() called");
|
|
22
|
+
};
|
|
23
|
+
process.on("SIGTERM", signalHandler);
|
|
24
|
+
process.on("SIGINT", signalHandler);
|
|
25
|
+
console.error("[Runner] Signal handlers registered");
|
|
26
|
+
try {
|
|
27
|
+
// Build runner options - cwd is already set by cli.ts via process.chdir()
|
|
28
|
+
const runnerOptions = {
|
|
29
|
+
model: options.model,
|
|
30
|
+
systemPrompt: options.systemPrompt,
|
|
31
|
+
maxTurns: options.maxTurns,
|
|
32
|
+
allowedTools: options.allowedTools,
|
|
33
|
+
resume: options.resume,
|
|
34
|
+
approvalDir: options.approvalDir,
|
|
35
|
+
};
|
|
36
|
+
const runner = createClaudeRunner(runnerOptions);
|
|
37
|
+
// Stream AI SDK UI messages to stdout
|
|
38
|
+
for await (const chunk of runner.run(options.userInput, abortController.signal)) {
|
|
39
|
+
// Write directly to stdout without modification
|
|
40
|
+
// This ensures the stream is a valid AI SDK UI stream
|
|
41
|
+
process.stdout.write(chunk);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
// Clean up signal handlers
|
|
46
|
+
process.off("SIGTERM", signalHandler);
|
|
47
|
+
process.off("SIGINT", signalHandler);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAwBlC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,OAAwB;IACrD,sDAAsD;IACtD,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;IAE9C,oCAAoC;IACpC,MAAM,aAAa,GAAG,GAAG,EAAE;QACzB,OAAO,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACnE,eAAe,CAAC,KAAK,EAAE,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC3D,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IACrC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IAEpC,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;IAErD,IAAI,CAAC;QACH,0EAA0E;QAC1E,MAAM,aAAa,GAAwB;YACzC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,WAAW,EAAE,OAAO,CAAC,WAAW;SACjC,CAAC;QAEF,MAAM,MAAM,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAC;QAEjD,sCAAsC;QACtC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,CAAC,GAAG,CAClC,OAAO,CAAC,SAAS,EACjB,eAAe,CAAC,MAAM,CACvB,EAAE,CAAC;YACF,gDAAgD;YAChD,sDAAsD;YACtD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;YAAS,CAAC;QACT,2BAA2B;QAC3B,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sandagent/runner-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SandAgent Runner CLI - Like gemini-cli or claude-code, runs in your local terminal with AI SDK UI streaming",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"sandagent": "./dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/vikadata/sandagent.git",
|
|
24
|
+
"directory": "apps/runner-cli"
|
|
25
|
+
},
|
|
26
|
+
"license": "Apache-2.0",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@sandagent/runner-claude": "0.1.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^20.10.0",
|
|
32
|
+
"esbuild": "^0.27.2",
|
|
33
|
+
"typescript": "^5.3.0",
|
|
34
|
+
"vitest": "^1.6.1"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc && pnpm bundle",
|
|
38
|
+
"build:bundle": "tsc && pnpm bundle",
|
|
39
|
+
"bundle": "esbuild src/cli.ts --bundle --platform=node --format=esm --outfile=dist/bundle.mjs",
|
|
40
|
+
"dev": "tsc --watch",
|
|
41
|
+
"clean": "rm -rf dist",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"lint": "echo 'no lint configured'",
|
|
44
|
+
"test": "vitest run --passWithNoTests"
|
|
45
|
+
}
|
|
46
|
+
}
|