@yoloship/ai 0.1.0 → 0.2.0-beta.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/dist/index.d.mts +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.mjs +147 -1
- package/package.json +4 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EventStream, ClaudeEvent, SpawnResult, McpServerConfig } from '@yoloship/claude-sdk';
|
|
2
|
-
export { EventStream, ClaudeEvent as RuntimeEvent, SpawnResult, classifyEvent, extractFileChange, isErrorEvent, isFileChangedEvent, isOutputEvent, isResultEvent, isThinkingEvent, isToolUseEvent, normalizeEvent } from '@yoloship/claude-sdk';
|
|
1
|
+
import { EventStream, ClaudeEvent, SpawnResult, McpServerConfig, ClaudeLanguage } from '@yoloship/claude-sdk';
|
|
2
|
+
export { EventStream, ClaudeEvent as RuntimeEvent, SpawnResult, ToolResultEvent, ToolUseEvent, classifyEvent, extractFileChange, isErrorEvent, isFileChangedEvent, isOutputEvent, isResultEvent, isThinkingEvent, isToolResultEvent, isToolUseEvent, normalizeEvent } from '@yoloship/claude-sdk';
|
|
3
3
|
|
|
4
4
|
type RuntimeEvent = ClaudeEvent;
|
|
5
5
|
type RuntimeProvider = 'anthropic' | 'openai' | 'openai-compatible' | 'custom';
|
|
@@ -22,6 +22,16 @@ interface RunOptions {
|
|
|
22
22
|
sessionId?: string;
|
|
23
23
|
/** Resume a prior CLI session by id (Claude `--resume`). */
|
|
24
24
|
resume?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Response language for textual outputs (logs, PR comments, reviews).
|
|
27
|
+
* Forwarded to the underlying runtime which injects a "respond in X"
|
|
28
|
+
* directive into the system prompt. Code identifiers must stay in English —
|
|
29
|
+
* enforced by an invariant injected from `@yoloship/action` agent prompts.
|
|
30
|
+
*
|
|
31
|
+
* Future runtimes (opencode, Codex) implement their own mapping or prompt
|
|
32
|
+
* injection; the field stays at the runtime-agnostic level.
|
|
33
|
+
*/
|
|
34
|
+
language?: ClaudeLanguage;
|
|
25
35
|
/** Called for every event emitted while the run is in progress. */
|
|
26
36
|
onEvent?: (event: RuntimeEvent) => void;
|
|
27
37
|
}
|
|
@@ -80,6 +90,14 @@ declare const PROVIDER_ENV_VAR: Record<RuntimeProvider, string | undefined>;
|
|
|
80
90
|
/**
|
|
81
91
|
* Default model id for each provider. Used when neither the per-agent
|
|
82
92
|
* `model` nor the run-level `model` override is set.
|
|
93
|
+
*
|
|
94
|
+
* NOT typed against `AnthropicModel`/`OpenaiModel` from @yoloship/shared:
|
|
95
|
+
* shared is `private: true` and @yoloship/ai is published, so a workspace
|
|
96
|
+
* dep here would break the publish chain. Drift protection lives in
|
|
97
|
+
* @yoloship/action's `validateRunLevelModel` (which DOES check the catalog)
|
|
98
|
+
* and in `agentProviderOverrideSchema` for per-agent overrides — by the
|
|
99
|
+
* time these defaults are observed, the run-level model has already been
|
|
100
|
+
* validated upstream.
|
|
83
101
|
*/
|
|
84
102
|
declare const DEFAULT_MODEL_BY_PROVIDER: Record<RuntimeProvider, string | undefined>;
|
|
85
103
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EventStream, ClaudeEvent, SpawnResult, McpServerConfig } from '@yoloship/claude-sdk';
|
|
2
|
-
export { EventStream, ClaudeEvent as RuntimeEvent, SpawnResult, classifyEvent, extractFileChange, isErrorEvent, isFileChangedEvent, isOutputEvent, isResultEvent, isThinkingEvent, isToolUseEvent, normalizeEvent } from '@yoloship/claude-sdk';
|
|
1
|
+
import { EventStream, ClaudeEvent, SpawnResult, McpServerConfig, ClaudeLanguage } from '@yoloship/claude-sdk';
|
|
2
|
+
export { EventStream, ClaudeEvent as RuntimeEvent, SpawnResult, ToolResultEvent, ToolUseEvent, classifyEvent, extractFileChange, isErrorEvent, isFileChangedEvent, isOutputEvent, isResultEvent, isThinkingEvent, isToolResultEvent, isToolUseEvent, normalizeEvent } from '@yoloship/claude-sdk';
|
|
3
3
|
|
|
4
4
|
type RuntimeEvent = ClaudeEvent;
|
|
5
5
|
type RuntimeProvider = 'anthropic' | 'openai' | 'openai-compatible' | 'custom';
|
|
@@ -22,6 +22,16 @@ interface RunOptions {
|
|
|
22
22
|
sessionId?: string;
|
|
23
23
|
/** Resume a prior CLI session by id (Claude `--resume`). */
|
|
24
24
|
resume?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Response language for textual outputs (logs, PR comments, reviews).
|
|
27
|
+
* Forwarded to the underlying runtime which injects a "respond in X"
|
|
28
|
+
* directive into the system prompt. Code identifiers must stay in English —
|
|
29
|
+
* enforced by an invariant injected from `@yoloship/action` agent prompts.
|
|
30
|
+
*
|
|
31
|
+
* Future runtimes (opencode, Codex) implement their own mapping or prompt
|
|
32
|
+
* injection; the field stays at the runtime-agnostic level.
|
|
33
|
+
*/
|
|
34
|
+
language?: ClaudeLanguage;
|
|
25
35
|
/** Called for every event emitted while the run is in progress. */
|
|
26
36
|
onEvent?: (event: RuntimeEvent) => void;
|
|
27
37
|
}
|
|
@@ -80,6 +90,14 @@ declare const PROVIDER_ENV_VAR: Record<RuntimeProvider, string | undefined>;
|
|
|
80
90
|
/**
|
|
81
91
|
* Default model id for each provider. Used when neither the per-agent
|
|
82
92
|
* `model` nor the run-level `model` override is set.
|
|
93
|
+
*
|
|
94
|
+
* NOT typed against `AnthropicModel`/`OpenaiModel` from @yoloship/shared:
|
|
95
|
+
* shared is `private: true` and @yoloship/ai is published, so a workspace
|
|
96
|
+
* dep here would break the publish chain. Drift protection lives in
|
|
97
|
+
* @yoloship/action's `validateRunLevelModel` (which DOES check the catalog)
|
|
98
|
+
* and in `agentProviderOverrideSchema` for per-agent overrides — by the
|
|
99
|
+
* time these defaults are observed, the run-level model has already been
|
|
100
|
+
* validated upstream.
|
|
83
101
|
*/
|
|
84
102
|
declare const DEFAULT_MODEL_BY_PROVIDER: Record<RuntimeProvider, string | undefined>;
|
|
85
103
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,147 @@
|
|
|
1
|
-
|
|
1
|
+
import { ensureClaude, spawnClaude, spawnClaudeBidirectional } from '@yoloship/claude-sdk';
|
|
2
|
+
export { EventStream, classifyEvent, extractFileChange, isErrorEvent, isFileChangedEvent, isOutputEvent, isResultEvent, isThinkingEvent, isToolResultEvent, isToolUseEvent, normalizeEvent } from '@yoloship/claude-sdk';
|
|
3
|
+
|
|
4
|
+
const CI_DEFAULTS = {
|
|
5
|
+
dangerouslySkipPermissions: true,
|
|
6
|
+
attribution: { commit: "", pr: "" },
|
|
7
|
+
autoMemoryEnabled: false
|
|
8
|
+
};
|
|
9
|
+
const CI_PAGER_ENV = {
|
|
10
|
+
GIT_PAGER: "cat",
|
|
11
|
+
GH_PAGER: "cat",
|
|
12
|
+
PAGER: "cat"
|
|
13
|
+
};
|
|
14
|
+
function toClaudeAuth(auth) {
|
|
15
|
+
if (!auth) {
|
|
16
|
+
return void 0;
|
|
17
|
+
}
|
|
18
|
+
return { apiKey: auth.apiKey };
|
|
19
|
+
}
|
|
20
|
+
class ClaudeRuntime {
|
|
21
|
+
id = "claude-code";
|
|
22
|
+
#ci;
|
|
23
|
+
constructor(opts = {}) {
|
|
24
|
+
this.#ci = opts.ci ?? false;
|
|
25
|
+
}
|
|
26
|
+
async ensure(options) {
|
|
27
|
+
await ensureClaude(options);
|
|
28
|
+
}
|
|
29
|
+
run(opts) {
|
|
30
|
+
const claudeOpts = this.#ci ? { ...CI_DEFAULTS, ...this.#toClaudeOptions(opts) } : this.#toClaudeOptions(opts);
|
|
31
|
+
const emitter = spawnClaude(claudeOpts, toClaudeAuth(opts.auth));
|
|
32
|
+
if (opts.onEvent) {
|
|
33
|
+
emitter.events.on(opts.onEvent);
|
|
34
|
+
}
|
|
35
|
+
return emitter.result;
|
|
36
|
+
}
|
|
37
|
+
runBidirectional(opts) {
|
|
38
|
+
const sessionOpts = this.#ci ? { ...CI_DEFAULTS, ...this.#toClaudeSessionOptions(opts) } : this.#toClaudeSessionOptions(opts);
|
|
39
|
+
const bidi = spawnClaudeBidirectional(sessionOpts, toClaudeAuth(opts.auth));
|
|
40
|
+
if (opts.onEvent) {
|
|
41
|
+
bidi.events.on(opts.onEvent);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
events: bidi.events,
|
|
45
|
+
sendTurn: (message) => bidi.sendMessage(message),
|
|
46
|
+
cancel: () => {
|
|
47
|
+
try {
|
|
48
|
+
bidi.process.kill();
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
close: () => bidi.close(),
|
|
53
|
+
result: bidi.result
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Canonical wire format for `--mcp-config`. Called internally by
|
|
58
|
+
* `#toClaudeSessionOptions` when `opts.mcpServers` is provided; also
|
|
59
|
+
* exposed on the `Runtime` interface for callers that need the
|
|
60
|
+
* serialised payload directly (e.g. writing an mcp-config file).
|
|
61
|
+
*/
|
|
62
|
+
buildMcpConfig(servers) {
|
|
63
|
+
return { mcpServers: servers };
|
|
64
|
+
}
|
|
65
|
+
/** Claude Code consumes `allowedTools` in its native shape — pass through. */
|
|
66
|
+
translateAllowedTools(tools) {
|
|
67
|
+
return tools;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Translate the runtime-agnostic `RunOptions` into Claude's native
|
|
71
|
+
* `ClaudeSessionOptions`. Routes `allowedTools` through
|
|
72
|
+
* `translateAllowedTools()` and `mcpServers` through `buildMcpConfig()`
|
|
73
|
+
* so the public interface methods are load-bearing on the internal
|
|
74
|
+
* execution path.
|
|
75
|
+
*/
|
|
76
|
+
#toClaudeSessionOptions(opts) {
|
|
77
|
+
const rest = {};
|
|
78
|
+
if (opts.systemPrompt !== void 0) {
|
|
79
|
+
rest.systemPrompt = opts.systemPrompt;
|
|
80
|
+
}
|
|
81
|
+
if (opts.model !== void 0) {
|
|
82
|
+
rest.model = opts.model;
|
|
83
|
+
}
|
|
84
|
+
if (opts.maxTurns !== void 0) {
|
|
85
|
+
rest.maxTurns = opts.maxTurns;
|
|
86
|
+
}
|
|
87
|
+
if (opts.allowedTools !== void 0) {
|
|
88
|
+
rest.allowedTools = this.translateAllowedTools(opts.allowedTools);
|
|
89
|
+
}
|
|
90
|
+
if (opts.mcpServers !== void 0) {
|
|
91
|
+
rest.mcpServers = this.buildMcpConfig(opts.mcpServers).mcpServers;
|
|
92
|
+
}
|
|
93
|
+
if (opts.cwd !== void 0) {
|
|
94
|
+
rest.cwd = opts.cwd;
|
|
95
|
+
}
|
|
96
|
+
if (this.#ci) {
|
|
97
|
+
rest.env = { ...CI_PAGER_ENV, ...opts.env ?? {} };
|
|
98
|
+
} else if (opts.env !== void 0) {
|
|
99
|
+
rest.env = opts.env;
|
|
100
|
+
}
|
|
101
|
+
if (opts.sessionId !== void 0) {
|
|
102
|
+
rest.sessionId = opts.sessionId;
|
|
103
|
+
}
|
|
104
|
+
if (opts.resume !== void 0) {
|
|
105
|
+
rest.resume = opts.resume;
|
|
106
|
+
}
|
|
107
|
+
if (opts.language !== void 0) {
|
|
108
|
+
rest.language = opts.language;
|
|
109
|
+
}
|
|
110
|
+
rest.settingSources = ["project", "local"];
|
|
111
|
+
return rest;
|
|
112
|
+
}
|
|
113
|
+
#toClaudeOptions(opts) {
|
|
114
|
+
return { prompt: opts.prompt, ...this.#toClaudeSessionOptions(opts) };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function getRuntime(runtime = "claude-code", opts = {}) {
|
|
119
|
+
switch (runtime) {
|
|
120
|
+
case "claude-code":
|
|
121
|
+
return new ClaudeRuntime({ ci: opts.ci });
|
|
122
|
+
case "opencode":
|
|
123
|
+
throw new Error("opencode runtime is not yet implemented \u2014 see YOL-204");
|
|
124
|
+
default: {
|
|
125
|
+
const unknown = runtime;
|
|
126
|
+
throw new Error(`Unknown runtime: ${String(unknown)}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const PROVIDER_ENV_VAR = {
|
|
132
|
+
"anthropic": "ANTHROPIC_API_KEY",
|
|
133
|
+
"openai": "OPENAI_API_KEY",
|
|
134
|
+
"openai-compatible": void 0,
|
|
135
|
+
"custom": void 0
|
|
136
|
+
};
|
|
137
|
+
const DEFAULT_MODEL_BY_PROVIDER = {
|
|
138
|
+
"anthropic": "claude-sonnet-4-6",
|
|
139
|
+
"openai": "gpt-4o-mini",
|
|
140
|
+
"openai-compatible": void 0,
|
|
141
|
+
"custom": void 0
|
|
142
|
+
};
|
|
143
|
+
function resolveModel(opts) {
|
|
144
|
+
return opts.runOverride ?? opts.agentModel ?? DEFAULT_MODEL_BY_PROVIDER[opts.provider];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { ClaudeRuntime, DEFAULT_MODEL_BY_PROVIDER, PROVIDER_ENV_VAR, getRuntime, resolveModel };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yoloship/ai",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0-beta.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Yoloship AI — runtime-agnostic coding-agent orchestration layer (consumes @yoloship/claude-sdk today, opencode next)",
|
|
7
7
|
"author": "Yoloship Team <team@yoloship.dev>",
|
|
@@ -33,15 +33,13 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"zod": "^4.4.3",
|
|
36
|
-
"@yoloship/claude-sdk": "0.
|
|
36
|
+
"@yoloship/claude-sdk": "0.2.0-beta.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@vitest/coverage-v8": "^4.1.4",
|
|
40
39
|
"cross-env": "^10.1.0",
|
|
41
|
-
"javascript-obfuscator": "^5.4.
|
|
40
|
+
"javascript-obfuscator": "^5.4.2",
|
|
42
41
|
"typescript": "^5.9.3",
|
|
43
|
-
"unbuild": "^3.5.0"
|
|
44
|
-
"vitest": "^4.1.4"
|
|
42
|
+
"unbuild": "^3.5.0"
|
|
45
43
|
},
|
|
46
44
|
"lint-staged": {
|
|
47
45
|
"*.{js,ts,vue,mjs,mts,cjs,md,yml,json}": "cross-env NODE_ENV=production eslint --fix"
|