@sapiom/agent-studio 0.0.1

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/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # @sapiom/agent-studio
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Sapiom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Agent Studio
2
+
3
+ Agent Studio is a local workspace for building, testing, deploying, and running
4
+ Sapiom agents with your own coding agent.
5
+
6
+ ```bash
7
+ npx @sapiom/agent-studio@latest [dir]
8
+ ```
9
+
10
+ The optional directory defaults to the current working directory. Every Agent
11
+ Studio launch flag is passed through unchanged, including `--port`, `--login`,
12
+ `--no-open`, `--no-auth`, `--no-telemetry`, `--no-session`, and `--state-root`.
13
+
14
+ This package is the branded public launcher. It delegates to an exact,
15
+ release-tested version of the `@sapiom/harness` implementation package; it does
16
+ not contain a second copy of the application. The supported direct command
17
+ continues to work:
18
+
19
+ ```bash
20
+ npx @sapiom/harness@latest [dir]
21
+ ```
22
+
23
+ Agent Studio requires Node.js 20 or newer and Claude Code or Codex on `PATH`.
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { AgentStudioLaunchError, launchAgentStudio } from "../lib/launcher.mjs";
4
+
5
+ try {
6
+ await launchAgentStudio();
7
+ } catch (error) {
8
+ if (error instanceof AgentStudioLaunchError) {
9
+ console.error(
10
+ `Agent Studio failed to launch [${error.code}]: ${error.message}`,
11
+ );
12
+ if (error.hint) console.error(error.hint);
13
+ } else {
14
+ const message = error instanceof Error ? error.message : String(error);
15
+ console.error(`Agent Studio failed to launch: ${message}`);
16
+ }
17
+ process.exitCode = 1;
18
+ }
@@ -0,0 +1,158 @@
1
+ import { spawn as nodeSpawn } from "node:child_process";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import path from "node:path";
5
+
6
+ const requireFromLauncher = createRequire(import.meta.url);
7
+
8
+ export class AgentStudioLaunchError extends Error {
9
+ constructor({ code, message, hint, cause }) {
10
+ super(message, cause === undefined ? undefined : { cause });
11
+ this.name = "AgentStudioLaunchError";
12
+ this.code = code;
13
+ this.hint = hint;
14
+ }
15
+ }
16
+
17
+ function defaultResolvePackageJson() {
18
+ return requireFromLauncher.resolve("@sapiom/harness/package.json");
19
+ }
20
+
21
+ /** Resolve the implementation bin without importing or duplicating Harness. */
22
+ export function resolveHarnessBin({
23
+ resolvePackageJson = defaultResolvePackageJson,
24
+ readFile = readFileSync,
25
+ fileExists = existsSync,
26
+ } = {}) {
27
+ let packageJsonPath;
28
+ try {
29
+ packageJsonPath = resolvePackageJson();
30
+ } catch (cause) {
31
+ throw new AgentStudioLaunchError({
32
+ code: "HARNESS_NOT_INSTALLED",
33
+ message:
34
+ "The @sapiom/harness implementation package could not be resolved.",
35
+ hint: "Reinstall with: npx --yes @sapiom/agent-studio@latest",
36
+ cause,
37
+ });
38
+ }
39
+
40
+ let manifest;
41
+ try {
42
+ manifest = JSON.parse(readFile(packageJsonPath, "utf8"));
43
+ } catch (cause) {
44
+ throw new AgentStudioLaunchError({
45
+ code: "HARNESS_MANIFEST_INVALID",
46
+ message: "The @sapiom/harness package manifest could not be read.",
47
+ hint: "Reinstall with: npx --yes @sapiom/agent-studio@latest",
48
+ cause,
49
+ });
50
+ }
51
+
52
+ const binEntry = manifest?.bin?.["sapiom-harness"];
53
+ if (typeof binEntry !== "string" || binEntry.length === 0) {
54
+ throw new AgentStudioLaunchError({
55
+ code: "HARNESS_BIN_NOT_FOUND",
56
+ message: "The @sapiom/harness manifest has no sapiom-harness bin entry.",
57
+ hint: "Reinstall with: npx --yes @sapiom/agent-studio@latest",
58
+ });
59
+ }
60
+
61
+ const binPath = path.resolve(path.dirname(packageJsonPath), binEntry);
62
+ if (!fileExists(binPath)) {
63
+ throw new AgentStudioLaunchError({
64
+ code: "HARNESS_BIN_NOT_FOUND",
65
+ message: `The sapiom-harness bin was not found at ${binPath}.`,
66
+ hint: "Reinstall with: npx --yes @sapiom/agent-studio@latest",
67
+ });
68
+ }
69
+
70
+ return binPath;
71
+ }
72
+
73
+ /** Convert child signal termination to the shell's conventional exit status. */
74
+ export function signalExitCode(signal) {
75
+ const numbers = {
76
+ SIGHUP: 1,
77
+ SIGINT: 2,
78
+ SIGQUIT: 3,
79
+ SIGKILL: 9,
80
+ SIGTERM: 15,
81
+ };
82
+ return 128 + (numbers[signal] ?? 0);
83
+ }
84
+
85
+ /**
86
+ * Launch Harness as an inherited child process.
87
+ *
88
+ * SIGINT is deliberately not forwarded: an interactive terminal delivers
89
+ * Ctrl-C to both processes in the foreground group, so forwarding it would
90
+ * signal Harness twice. SIGTERM and SIGHUP do need explicit forwarding.
91
+ */
92
+ export async function launchAgentStudio({
93
+ argv = process.argv.slice(2),
94
+ cwd = process.cwd(),
95
+ env = process.env,
96
+ execPath = process.execPath,
97
+ processRef = process,
98
+ spawn = nodeSpawn,
99
+ resolver,
100
+ } = {}) {
101
+ const harnessBin = resolveHarnessBin(resolver);
102
+
103
+ await new Promise((resolve, reject) => {
104
+ let child;
105
+ try {
106
+ child = spawn(execPath, [harnessBin, ...argv], {
107
+ cwd,
108
+ env,
109
+ stdio: "inherit",
110
+ });
111
+ } catch (cause) {
112
+ reject(
113
+ new AgentStudioLaunchError({
114
+ code: "HARNESS_SPAWN_FAILED",
115
+ message: `Could not start sapiom-harness: ${cause instanceof Error ? cause.message : String(cause)}`,
116
+ cause,
117
+ }),
118
+ );
119
+ return;
120
+ }
121
+
122
+ let settled = false;
123
+ const forwardSigterm = () => child.kill("SIGTERM");
124
+ const forwardSighup = () => child.kill("SIGHUP");
125
+ const cleanup = () => {
126
+ processRef.off("SIGTERM", forwardSigterm);
127
+ processRef.off("SIGHUP", forwardSighup);
128
+ };
129
+
130
+ processRef.on("SIGTERM", forwardSigterm);
131
+ processRef.on("SIGHUP", forwardSighup);
132
+
133
+ child.once("error", (cause) => {
134
+ if (settled) return;
135
+ settled = true;
136
+ cleanup();
137
+ reject(
138
+ new AgentStudioLaunchError({
139
+ code: "HARNESS_SPAWN_FAILED",
140
+ message: `Could not start sapiom-harness: ${cause.message}`,
141
+ cause,
142
+ }),
143
+ );
144
+ });
145
+
146
+ child.once("close", (code, signal) => {
147
+ if (settled) return;
148
+ settled = true;
149
+ cleanup();
150
+ if (signal) {
151
+ processRef.exitCode = signalExitCode(signal);
152
+ } else if (code !== null && code !== 0) {
153
+ processRef.exitCode = code;
154
+ }
155
+ resolve();
156
+ });
157
+ });
158
+ }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@sapiom/agent-studio",
3
+ "version": "0.0.1",
4
+ "description": "Agent Studio — build, test, deploy, and run Sapiom agents with your coding agent in a local workspace.",
5
+ "keywords": [
6
+ "sapiom",
7
+ "agent-studio",
8
+ "claude",
9
+ "codex",
10
+ "agents"
11
+ ],
12
+ "homepage": "https://github.com/sapiom/sapiom-js/tree/main/packages/agent-studio#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/sapiom/sapiom-js/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/sapiom/sapiom-js.git",
19
+ "directory": "packages/agent-studio"
20
+ },
21
+ "license": "MIT",
22
+ "author": "Sapiom",
23
+ "type": "module",
24
+ "bin": {
25
+ "agent-studio": "./bin/agent-studio.mjs"
26
+ },
27
+ "files": [
28
+ "bin",
29
+ "lib",
30
+ "README.md",
31
+ "LICENSE",
32
+ "CHANGELOG.md"
33
+ ],
34
+ "dependencies": {
35
+ "@sapiom/harness": "0.2.6"
36
+ },
37
+ "engines": {
38
+ "node": ">=20.0.0"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "scripts": {
44
+ "build": "node --check bin/agent-studio.mjs && node --check lib/launcher.mjs",
45
+ "test": "node --test test/*.test.mjs"
46
+ }
47
+ }