osuite 2.9.4 → 2.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +8 -1
  2. package/cli.js +197 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # OSuite SDK (v2.9.4)
1
+ # OSuite SDK (v2.9.6)
2
2
 
3
3
  **Governed action SDK for AI agents.**
4
4
 
@@ -11,6 +11,13 @@ The OSuite SDK helps teams route approvals, record governed decisions, and produ
11
11
  npm install osuite
12
12
  ```
13
13
 
14
+ ### One-command runtime connect
15
+ ```bash
16
+ curl -fsSL https://studio.osuite.ai/install.sh | bash
17
+ ```
18
+
19
+ The installer detects Codex, Claude Code, SDK, or MCP-style projects, opens a browser handoff, and writes the approved runtime environment into the project (`.codex/.env`, `.claude/.env`, or `.osuite/.env`). API keys remain available as a fallback, but the normal path is terminal start -> Studio approval -> terminal auto-finish.
20
+
14
21
  ### Python
15
22
  ```bash
16
23
  pip install requests
package/cli.js CHANGED
@@ -162,6 +162,149 @@ function buildConnectHandoffUrl({ baseUrl, runtime, code }) {
162
162
  return url.toString();
163
163
  }
164
164
 
165
+ function defaultAgentIdForRuntime(runtime) {
166
+ if (runtime === 'codex') return 'codex-runtime';
167
+ if (runtime === 'claude') return 'claude-code-runtime';
168
+ if (runtime === 'mcp') return 'mcp-runtime';
169
+ return 'sdk-runtime';
170
+ }
171
+
172
+ function sanitizeConfiguredAgentId(runtime, agentId) {
173
+ const value = String(agentId || '').trim();
174
+ if (!value) return '';
175
+ const knownDefaults = {
176
+ codex: 'codex-runtime',
177
+ claude: 'claude-code-runtime',
178
+ mcp: 'mcp-runtime',
179
+ sdk: 'sdk-runtime',
180
+ };
181
+ const foreignDefault = Object.entries(knownDefaults).some(([otherRuntime, defaultId]) => (
182
+ otherRuntime !== runtime && value === defaultId
183
+ ));
184
+ return foreignDefault ? '' : value;
185
+ }
186
+
187
+ function runtimeMatchesConfiguredAdapter(runtime, adapterId) {
188
+ const adapter = String(adapterId || '').trim().toLowerCase();
189
+ if (!adapter) return false;
190
+ if (runtime === 'codex') return adapter === 'codex_hooks';
191
+ if (runtime === 'claude') return adapter === 'claude_code_hooks' || adapter === 'claude_hooks';
192
+ if (runtime === 'mcp') return adapter.includes('mcp');
193
+ if (runtime === 'sdk') return ['sdk', 'framework_sdk', 'inline_sdk'].includes(adapter);
194
+ return false;
195
+ }
196
+
197
+ function envPathForRuntime(runtime) {
198
+ if (runtime === 'codex') return '.codex/.env';
199
+ if (runtime === 'claude') return '.claude/.env';
200
+ return '.osuite/.env';
201
+ }
202
+
203
+ function orderedEnvEntries(env = {}) {
204
+ const preferred = [
205
+ 'OSUITE_BASE_URL',
206
+ 'OSUITE_API_KEY',
207
+ 'OSUITE_AGENT_ID',
208
+ 'OSUITE_RUNTIME_ADAPTER_ID',
209
+ 'OSUITE_SIGNATURE_MODE',
210
+ ];
211
+ const seen = new Set();
212
+ const entries = [];
213
+ preferred.forEach((key) => {
214
+ if (env[key] !== undefined && env[key] !== null && env[key] !== '') {
215
+ seen.add(key);
216
+ entries.push([key, env[key]]);
217
+ }
218
+ });
219
+ Object.keys(env)
220
+ .sort()
221
+ .forEach((key) => {
222
+ if (!seen.has(key) && env[key] !== undefined && env[key] !== null && env[key] !== '') {
223
+ entries.push([key, env[key]]);
224
+ }
225
+ });
226
+ return entries;
227
+ }
228
+
229
+ function formatEnvBody(env = {}) {
230
+ return `${orderedEnvEntries(env)
231
+ .map(([key, value]) => `${key}=${String(value).replace(/\n/g, '')}`)
232
+ .join('\n')}\n`;
233
+ }
234
+
235
+ function parsePositiveInt(value, fallback) {
236
+ const parsed = Number.parseInt(value, 10);
237
+ if (!Number.isFinite(parsed) || parsed < 0) return fallback;
238
+ return parsed;
239
+ }
240
+
241
+ function sleep(ms) {
242
+ return new Promise((resolve) => setTimeout(resolve, ms));
243
+ }
244
+
245
+ async function postJson(url, body) {
246
+ const response = await fetch(url, {
247
+ method: 'POST',
248
+ headers: { 'content-type': 'application/json' },
249
+ body: JSON.stringify(body || {}),
250
+ });
251
+ const text = await response.text();
252
+ let payload = {};
253
+ if (text) {
254
+ try {
255
+ payload = JSON.parse(text);
256
+ } catch {
257
+ payload = { raw: text };
258
+ }
259
+ }
260
+ return { response, payload };
261
+ }
262
+
263
+ async function startDeviceConnect({ baseUrl, runtime, agentId }) {
264
+ const { response, payload } = await postJson(`${normalizedBaseUrl(baseUrl)}/api/onboarding/device-connect/start`, {
265
+ runtime,
266
+ agent_id: agentId,
267
+ project_root: process.cwd(),
268
+ });
269
+ if (!response.ok) {
270
+ throw new Error(payload.error || `Unable to start browser handoff: HTTP ${response.status}`);
271
+ }
272
+ if (!payload.device_code || !payload.poll_token || !payload.user_code) {
273
+ throw new Error('Studio did not return a complete device-connect payload.');
274
+ }
275
+ return payload;
276
+ }
277
+
278
+ async function pollDeviceConnect({ baseUrl, deviceCode, pollToken, timeoutMs, intervalMs }) {
279
+ const deadline = Date.now() + timeoutMs;
280
+ while (Date.now() <= deadline) {
281
+ const { response, payload } = await postJson(`${normalizedBaseUrl(baseUrl)}/api/onboarding/device-connect/poll`, {
282
+ device_code: deviceCode,
283
+ poll_token: pollToken,
284
+ });
285
+
286
+ if (response.status === 200 && payload.status === 'approved' && payload.credential?.env) {
287
+ return payload.credential;
288
+ }
289
+ if (response.status === 202 || payload.status === 'pending') {
290
+ const serverInterval = Number(payload.interval_seconds || 0) * 1000;
291
+ await sleep(serverInterval > 0 ? Math.max(intervalMs, serverInterval) : intervalMs);
292
+ continue;
293
+ }
294
+ if (response.status === 410 || payload.status === 'expired') {
295
+ throw new Error('Browser handoff expired. Run osuite connect again.');
296
+ }
297
+ if (response.status === 409 || payload.status === 'consumed') {
298
+ throw new Error(payload.error || 'Browser handoff was already consumed.');
299
+ }
300
+ if (response.status === 404) {
301
+ throw new Error('Browser handoff was not found. Run osuite connect again.');
302
+ }
303
+ throw new Error(payload.error || `Unable to finish browser handoff: HTTP ${response.status}`);
304
+ }
305
+ return null;
306
+ }
307
+
165
308
  function projectFilePath(relativePath) {
166
309
  const clean = String(relativePath || '').replace(/^\/+/, '');
167
310
  const root = path.resolve(process.cwd());
@@ -554,21 +697,37 @@ async function connect(target = 'auto', args = {}) {
554
697
  const config = readConfig();
555
698
  const runtime = detectRuntimeTarget(target);
556
699
  const baseUrl = normalizedBaseUrl(args['base-url'] || config.baseUrl || DEFAULT_BASE_URL);
557
- const code = String(args.code || generateConnectCode()).trim() || generateConnectCode();
558
- const handoffUrl = buildConnectHandoffUrl({ baseUrl, runtime, code });
700
+ const configuredAgentId = sanitizeConfiguredAgentId(
701
+ runtime,
702
+ runtimeMatchesConfiguredAdapter(runtime, config.runtimeAdapterId)
703
+ ? envValue('OSUITE_AGENT_ID', 'DASHCLAW_AGENT_ID')
704
+ : '',
705
+ );
706
+ const agentId = String(args['agent-id'] || configuredAgentId || defaultAgentIdForRuntime(runtime));
707
+ const dryRunCode = String(args.code || generateConnectCode()).trim() || generateConnectCode();
708
+ let connectPayload = null;
709
+ let code = dryRunCode;
710
+ let handoffUrl = buildConnectHandoffUrl({ baseUrl, runtime, code });
559
711
  const hasApiKey = Boolean(config.apiKey);
560
712
 
713
+ if (!args['dry-run']) {
714
+ connectPayload = await startDeviceConnect({ baseUrl, runtime, agentId });
715
+ code = connectPayload.user_code;
716
+ handoffUrl = connectPayload.verification_uri_complete || buildConnectHandoffUrl({ baseUrl, runtime, code });
717
+ }
718
+
561
719
  write(c('OSuite Connect', `${ANSI.bold}${ANSI.cyan}`));
562
720
  write(c('Project-root setup for governed agent actions.', ANSI.dim));
563
721
  write('');
564
722
  write(`Detected runtime ${runtime}`);
565
723
  write(`Project root ${process.cwd()}`);
566
724
  write(`Browser handoff ${handoffUrl}`);
725
+ write(`One-time code ${code}`);
567
726
  write('');
568
727
  write(c('What happens next', ANSI.bold));
569
- write(' 1. Open the browser handoff URL and choose the workspace that should own this runtime.');
570
- write(' 2. OSuite prepares the runtime identity and project hook lane for the detected agent.');
571
- write(' 3. Run osuite doctor, then trigger one low-risk governed action from the same project root.');
728
+ write(' 1. Open the browser handoff URL and approve this terminal connection in Studio.');
729
+ write(' 2. OSuite prepares the runtime identity, project hook lane, and signed env for this project.');
730
+ write(' 3. Return here; the CLI will finish automatically and then you can run osuite doctor.');
572
731
  write('');
573
732
 
574
733
  if (PROJECT_BOOTSTRAPS[runtime]) {
@@ -584,6 +743,39 @@ async function connect(target = 'auto', args = {}) {
584
743
  if (runtime === 'mcp') write(' Wrap consequential tool calls with OSuite preflight, wait-for-approval, and complete-action steps.');
585
744
  }
586
745
 
746
+ if (!args['dry-run'] && connectPayload) {
747
+ const timeoutMs = parsePositiveInt(args['poll-timeout-ms'], 180000);
748
+ const intervalMs = parsePositiveInt(
749
+ args['poll-interval-ms'],
750
+ Math.max(1000, Number(connectPayload.interval_seconds || 2) * 1000),
751
+ );
752
+
753
+ write('');
754
+ write(c('Waiting for browser approval', ANSI.bold));
755
+ write(` Code ${code} expires in about ${Math.round(Number(connectPayload.expires_in || 600) / 60)} minutes.`);
756
+
757
+ const credential = await pollDeviceConnect({
758
+ baseUrl,
759
+ deviceCode: connectPayload.device_code,
760
+ pollToken: connectPayload.poll_token,
761
+ timeoutMs,
762
+ intervalMs,
763
+ });
764
+
765
+ if (credential?.env) {
766
+ const envPath = envPathForRuntime(runtime);
767
+ const result = writeProjectFile(envPath, formatEnvBody(credential.env), { force: true });
768
+ write('');
769
+ write(c('Connected to OSuite', ANSI.green));
770
+ write(` ${result.status === 'written' ? 'wrote' : 'kept'} ${result.relativePath}`);
771
+ write(' Run osuite doctor, then start the agent from this project root.');
772
+ } else {
773
+ write('');
774
+ write(c('Browser approval not completed before the timeout.', ANSI.yellow));
775
+ write(' Keep the browser handoff open or run osuite connect again.');
776
+ }
777
+ }
778
+
587
779
  write('');
588
780
  write(c('API key fallback', ANSI.bold));
589
781
  if (hasApiKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "osuite",
3
- "version": "2.9.4",
3
+ "version": "2.9.6",
4
4
  "description": "OSuite governed action SDK for AI agents. Approve, replay, prove, and verify runtime decisions.",
5
5
  "type": "module",
6
6
  "publishConfig": {