@vibesdotdev/integrations-anthropic 0.0.0-stage → 1.0.0-rc.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 +126 -0
- package/README.md +57 -2
- package/dist/ai/anthropic-router-codec.d.ts +32 -0
- package/dist/ai/anthropic-router-codec.d.ts.map +1 -0
- package/dist/ai/anthropic-router-codec.js +321 -0
- package/dist/ai/anthropic-router-codec.js.map +1 -0
- package/dist/ai/anthropic.plugin.d.ts +6 -0
- package/dist/ai/anthropic.plugin.d.ts.map +1 -0
- package/dist/ai/anthropic.plugin.js +116 -0
- package/dist/ai/anthropic.plugin.js.map +1 -0
- package/dist/ai/catalog.d.ts +87 -0
- package/dist/ai/catalog.d.ts.map +1 -0
- package/dist/ai/catalog.js +64 -0
- package/dist/ai/catalog.js.map +1 -0
- package/dist/ai/claude-code-session.d.ts +56 -0
- package/dist/ai/claude-code-session.d.ts.map +1 -0
- package/dist/ai/claude-code-session.js +75 -0
- package/dist/ai/claude-code-session.js.map +1 -0
- package/dist/ai/claude-code-turn-env.d.ts +10 -0
- package/dist/ai/claude-code-turn-env.d.ts.map +1 -0
- package/dist/ai/claude-code-turn-env.js +19 -0
- package/dist/ai/claude-code-turn-env.js.map +1 -0
- package/dist/ai/hostile.d.ts +23 -0
- package/dist/ai/hostile.d.ts.map +1 -0
- package/dist/ai/hostile.js +22 -0
- package/dist/ai/hostile.js.map +1 -0
- package/dist/ai/index.d.ts +4 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +4 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/metadata/assets/logos/providers/anthropic.svg +1 -0
- package/dist/ai/metadata/provider-models/anthropic/anthropic-claude-3-5-haiku-20241022.json +77 -0
- package/dist/ai/metadata/provider-models/anthropic/anthropic-claude-3-5-sonnet-20241022.json +42 -0
- package/dist/ai/metadata/provider-models/anthropic/anthropic-claude-4-opus-20250514.json +79 -0
- package/dist/ai/metadata/provider-models/anthropic/anthropic-claude-4-sonnet-20250514.json +79 -0
- package/dist/ai/metadata/provider-models/anthropic/anthropic-claude-haiku-4-5.json +80 -0
- package/dist/ai/metadata/provider-models/anthropic/anthropic-claude-haiku-5-5.json +39 -0
- package/dist/ai/metadata/provider-models/anthropic/anthropic-claude-opus-4-1.json +78 -0
- package/dist/ai/metadata/provider-models/anthropic/anthropic-claude-opus-4-5.json +80 -0
- package/dist/ai/metadata/provider-models/anthropic/anthropic-claude-opus-4-6.json +80 -0
- package/dist/ai/metadata/provider-models/anthropic/anthropic-claude-opus-4-7.json +81 -0
- package/dist/ai/metadata/provider-models/anthropic/anthropic-claude-sonnet-4-5.json +80 -0
- package/dist/ai/metadata/provider-models/anthropic/anthropic-claude-sonnet-4-6.json +80 -0
- package/dist/ai/metadata/providers/anthropic.json +22 -0
- package/dist/ai/providers/anthropic/anthropic.provider.impl.d.ts +62 -0
- package/dist/ai/providers/anthropic/anthropic.provider.impl.d.ts.map +1 -0
- package/dist/ai/providers/anthropic/anthropic.provider.impl.js +430 -0
- package/dist/ai/providers/anthropic/anthropic.provider.impl.js.map +1 -0
- package/dist/ai/providers/anthropic/detection/index.d.ts +8 -0
- package/dist/ai/providers/anthropic/detection/index.d.ts.map +1 -0
- package/dist/ai/providers/anthropic/detection/index.js +8 -0
- package/dist/ai/providers/anthropic/detection/index.js.map +1 -0
- package/dist/ai/providers/anthropic/detection/system.d.ts +12 -0
- package/dist/ai/providers/anthropic/detection/system.d.ts.map +1 -0
- package/dist/ai/providers/anthropic/detection/system.js +34 -0
- package/dist/ai/providers/anthropic/detection/system.js.map +1 -0
- package/dist/ai/providers/anthropic/docs/ai.providers.anthropic.docs.descriptor.d.ts +4 -0
- package/dist/ai/providers/anthropic/docs/ai.providers.anthropic.docs.descriptor.d.ts.map +1 -0
- package/dist/ai/providers/anthropic/docs/ai.providers.anthropic.docs.descriptor.js +212 -0
- package/dist/ai/providers/anthropic/docs/ai.providers.anthropic.docs.descriptor.js.map +1 -0
- package/dist/ai/providers/anthropic/index.d.ts +4 -0
- package/dist/ai/providers/anthropic/index.d.ts.map +1 -0
- package/dist/ai/providers/anthropic/index.js +4 -0
- package/dist/ai/providers/anthropic/index.js.map +1 -0
- package/dist/ai/providers/anthropic/recommendations.d.ts +24 -0
- package/dist/ai/providers/anthropic/recommendations.d.ts.map +1 -0
- package/dist/ai/providers/anthropic/recommendations.js +192 -0
- package/dist/ai/providers/anthropic/recommendations.js.map +1 -0
- package/dist/ai/providers/cloud/frontier/anthropic/config/config.anthropic.descriptor.d.ts +4194 -0
- package/dist/ai/providers/cloud/frontier/anthropic/config/config.anthropic.descriptor.d.ts.map +1 -0
- package/dist/ai/providers/cloud/frontier/anthropic/config/config.anthropic.descriptor.js +52 -0
- package/dist/ai/providers/cloud/frontier/anthropic/config/config.anthropic.descriptor.js.map +1 -0
- package/dist/ai/providers/cloud/frontier/anthropic/config/schemas/index.d.ts +46 -0
- package/dist/ai/providers/cloud/frontier/anthropic/config/schemas/index.d.ts.map +1 -0
- package/dist/ai/providers/cloud/frontier/anthropic/config/schemas/index.js +22 -0
- package/dist/ai/providers/cloud/frontier/anthropic/config/schemas/index.js.map +1 -0
- package/dist/ai/providers/cloud/frontier/anthropic/index.d.ts +5 -0
- package/dist/ai/providers/cloud/frontier/anthropic/index.d.ts.map +1 -0
- package/dist/ai/providers/cloud/frontier/anthropic/index.js +4 -0
- package/dist/ai/providers/cloud/frontier/anthropic/index.js.map +1 -0
- package/dist/ai/providers/cloud/frontier/anthropic/provider.anthropic.descriptor.d.ts +183 -0
- package/dist/ai/providers/cloud/frontier/anthropic/provider.anthropic.descriptor.d.ts.map +1 -0
- package/dist/ai/providers/cloud/frontier/anthropic/provider.anthropic.descriptor.js +115 -0
- package/dist/ai/providers/cloud/frontier/anthropic/provider.anthropic.descriptor.js.map +1 -0
- package/dist/ai/specs/anthropic-messages/anthropic-messages.failures.d.ts +46 -0
- package/dist/ai/specs/anthropic-messages/anthropic-messages.failures.d.ts.map +1 -0
- package/dist/ai/specs/anthropic-messages/anthropic-messages.failures.js +183 -0
- package/dist/ai/specs/anthropic-messages/anthropic-messages.failures.js.map +1 -0
- package/dist/ai/specs/anthropic-messages/anthropic-messages.spec.descriptor.d.ts +34 -0
- package/dist/ai/specs/anthropic-messages/anthropic-messages.spec.descriptor.d.ts.map +1 -0
- package/dist/ai/specs/anthropic-messages/anthropic-messages.spec.descriptor.js +29 -0
- package/dist/ai/specs/anthropic-messages/anthropic-messages.spec.descriptor.js.map +1 -0
- package/dist/ai/specs/anthropic-messages/anthropic-messages.spec.impl.d.ts +48 -0
- package/dist/ai/specs/anthropic-messages/anthropic-messages.spec.impl.d.ts.map +1 -0
- package/dist/ai/specs/anthropic-messages/anthropic-messages.spec.impl.js +557 -0
- package/dist/ai/specs/anthropic-messages/anthropic-messages.spec.impl.js.map +1 -0
- package/dist/ai/specs/claude-code-exec/claude-code-exec.spec.descriptor.d.ts +26 -0
- package/dist/ai/specs/claude-code-exec/claude-code-exec.spec.descriptor.d.ts.map +1 -0
- package/dist/ai/specs/claude-code-exec/claude-code-exec.spec.descriptor.js +15 -0
- package/dist/ai/specs/claude-code-exec/claude-code-exec.spec.descriptor.js.map +1 -0
- package/dist/ai/specs/claude-code-exec/claude-code-exec.spec.impl.d.ts +35 -0
- package/dist/ai/specs/claude-code-exec/claude-code-exec.spec.impl.d.ts.map +1 -0
- package/dist/ai/specs/claude-code-exec/claude-code-exec.spec.impl.js +210 -0
- package/dist/ai/specs/claude-code-exec/claude-code-exec.spec.impl.js.map +1 -0
- package/dist/external/acp-server.consumer.plugin.d.ts +3 -0
- package/dist/external/acp-server.consumer.plugin.d.ts.map +1 -0
- package/dist/external/acp-server.consumer.plugin.js +29 -0
- package/dist/external/acp-server.consumer.plugin.js.map +1 -0
- package/dist/external/acp-server.d.ts +19 -0
- package/dist/external/acp-server.d.ts.map +1 -0
- package/dist/external/acp-server.js +198 -0
- package/dist/external/acp-server.js.map +1 -0
- package/dist/external/claude-code-hooks.d.ts +51 -0
- package/dist/external/claude-code-hooks.d.ts.map +1 -0
- package/dist/external/claude-code-hooks.js +252 -0
- package/dist/external/claude-code-hooks.js.map +1 -0
- package/dist/external/claude-code-installer.d.ts +10 -0
- package/dist/external/claude-code-installer.d.ts.map +1 -0
- package/dist/external/claude-code-installer.js +604 -0
- package/dist/external/claude-code-installer.js.map +1 -0
- package/dist/external/claude-code-operations.d.ts +217 -0
- package/dist/external/claude-code-operations.d.ts.map +1 -0
- package/dist/external/claude-code-operations.js +101 -0
- package/dist/external/claude-code-operations.js.map +1 -0
- package/dist/external/claude-code-plugin.json +7 -0
- package/dist/external/claude-code-presets.d.ts +813 -0
- package/dist/external/claude-code-presets.d.ts.map +1 -0
- package/dist/external/claude-code-presets.js +157 -0
- package/dist/external/claude-code-presets.js.map +1 -0
- package/dist/external/claude-code.descriptor.d.ts +160 -0
- package/dist/external/claude-code.descriptor.d.ts.map +1 -0
- package/dist/external/claude-code.descriptor.js +5 -0
- package/dist/external/claude-code.descriptor.js.map +1 -0
- package/dist/external/claude-code.manifest.d.ts +5 -0
- package/dist/external/claude-code.manifest.d.ts.map +1 -0
- package/dist/external/claude-code.manifest.js +205 -0
- package/dist/external/claude-code.manifest.js.map +1 -0
- package/dist/external/external.plugin.d.ts +6 -0
- package/dist/external/external.plugin.d.ts.map +1 -0
- package/dist/external/external.plugin.js +56 -0
- package/dist/external/external.plugin.js.map +1 -0
- package/dist/external/index.d.ts +6 -0
- package/dist/external/index.d.ts.map +1 -0
- package/dist/external/index.js +6 -0
- package/dist/external/index.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/package.json +108 -4
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type AISpecInterface, type DecodedEvent, type SpecCallContext, type WireRequest, type WireResponseChunk } from '@vibesdotdev/ai/specs/interfaces';
|
|
2
|
+
import type { GenerationRequest } from '@vibesdotdev/ai/interfaces';
|
|
3
|
+
import type { Modality } from '@vibesdotdev/ai/models/schemas';
|
|
4
|
+
/** The most stdout one turn is read from (a `claude -p` JSON answer is far below it); beyond it the turn fails. */
|
|
5
|
+
export declare const MAX_CLAUDE_STDOUT_BYTES: number;
|
|
6
|
+
declare class ClaudeCodeExecSpec implements AISpecInterface {
|
|
7
|
+
readonly descriptor: {
|
|
8
|
+
id: string;
|
|
9
|
+
kind: "ai/spec";
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
modalities: ("text" | "image" | "speech" | "audio" | "video" | "embedding" | "transcription" | "ocr" | "evaluation")[];
|
|
13
|
+
streamFraming: "none" | "sse" | "sse-named" | "ndjson" | "binary-chunked" | "ws-frame";
|
|
14
|
+
toolCallEnvelope: string;
|
|
15
|
+
transports: string[];
|
|
16
|
+
external: boolean;
|
|
17
|
+
priority: number;
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
capabilities?: ("streaming" | "json_mode" | "text_generation" | "chat_completion" | "function_calling" | "embedding_generation" | "image_generation_text_to_image" | "image_generation_image_to_image" | "image_generation_inpainting" | "image_generation_outpainting" | "image_upscaling" | "image_editing_via_instructions" | "audio_generation_text_to_speech" | "audio_generation_voice_cloning" | "audio_generation_music" | "audio_generation_sound_effects" | "audio_transcription" | "audio_transcription_realtime" | "video_generation_text_to_video" | "workflow_execution" | "code_generation" | "image_understanding" | "structured_evaluation")[] | undefined;
|
|
20
|
+
imageControls?: {
|
|
21
|
+
steps: boolean;
|
|
22
|
+
cfg: boolean;
|
|
23
|
+
sampler: boolean;
|
|
24
|
+
scheduler: boolean;
|
|
25
|
+
negativePrompt: boolean;
|
|
26
|
+
seed: boolean;
|
|
27
|
+
} | undefined;
|
|
28
|
+
tags?: string[] | undefined;
|
|
29
|
+
};
|
|
30
|
+
encodeRequest<M extends Modality>(request: GenerationRequest<M>, context: SpecCallContext): WireRequest;
|
|
31
|
+
decodeResponse<M extends Modality>(chunks: AsyncIterable<WireResponseChunk>, request: GenerationRequest<M>, context: SpecCallContext): AsyncIterable<DecodedEvent<M>>;
|
|
32
|
+
}
|
|
33
|
+
declare const _default: ClaudeCodeExecSpec;
|
|
34
|
+
export default _default;
|
|
35
|
+
//# sourceMappingURL=claude-code-exec.spec.impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code-exec.spec.impl.d.ts","sourceRoot":"","sources":["../../../../src/ai/specs/claude-code-exec/claude-code-exec.spec.impl.ts"],"names":[],"mappings":"AACA,OAAO,EAIN,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAEX,iBAAiB,EAGjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAkB/D,mHAAmH;AACnH,eAAO,MAAM,uBAAuB,QAAkB,CAAC;AAqBvD,cAAM,kBAAmB,YAAW,eAAe;IAClD,QAAQ,CAAC,UAAU;;;;;;;;;;;;;;;;;;;;;;MAAc;IAEjC,aAAa,CAAC,CAAC,SAAS,QAAQ,EAC/B,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC7B,OAAO,EAAE,eAAe,GACtB,WAAW;IAuCP,cAAc,CAAC,CAAC,SAAS,QAAQ,EACvC,MAAM,EAAE,aAAa,CAAC,iBAAiB,CAAC,EACxC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC7B,OAAO,EAAE,eAAe,GACtB,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CAqCjC;;AAiGD,wBAAwC"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { concatAll, isTextRequest, textResultEvent } from '@vibesdotdev/ai/specs/interfaces';
|
|
3
|
+
import { CapabilityError, CaughtFailureSchema, isCapabilityError } from '@vibesdotdev/kernel';
|
|
4
|
+
import descriptor from "./claude-code-exec.spec.descriptor.js";
|
|
5
|
+
import { CLAUDE_CODE_SUBSCRIPTION_ENV, withClaudeCodeSubscriptionPolicy } from "../../claude-code-session.js";
|
|
6
|
+
import { providerTextCause } from '@vibesdotdev/ai/utils/provider-text';
|
|
7
|
+
/** Claude Code prints its answer under one of these members; a member of another type reads as absent. */
|
|
8
|
+
const ClaudeOutputSchema = z.looseObject({
|
|
9
|
+
is_error: z.boolean().optional().catch(undefined),
|
|
10
|
+
result: z.string().optional().catch(undefined),
|
|
11
|
+
response: z.string().optional().catch(undefined),
|
|
12
|
+
content: z.string().optional().catch(undefined),
|
|
13
|
+
text: z.string().optional().catch(undefined)
|
|
14
|
+
});
|
|
15
|
+
/** The most stdout one turn is read from (a `claude -p` JSON answer is far below it); beyond it the turn fails. */
|
|
16
|
+
export const MAX_CLAUDE_STDOUT_BYTES = 8 * 1024 * 1024;
|
|
17
|
+
/** The request fields a one-turn, tool-free `claude -p` cannot honour: sampling and output limits it has no flag for. */
|
|
18
|
+
const UNHONOURED_FIELDS = [
|
|
19
|
+
'temperature',
|
|
20
|
+
'topP',
|
|
21
|
+
'topK',
|
|
22
|
+
'maxTokens',
|
|
23
|
+
'stopSequences',
|
|
24
|
+
'frequencyPenalty',
|
|
25
|
+
'presencePenalty'
|
|
26
|
+
];
|
|
27
|
+
function refuse(reason, message, fields) {
|
|
28
|
+
return new CapabilityError(message, 'INVALID_INPUT', {
|
|
29
|
+
reason,
|
|
30
|
+
retryable: false,
|
|
31
|
+
details: fields ? { fields: [...fields] } : undefined
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
class ClaudeCodeExecSpec {
|
|
35
|
+
descriptor = descriptor;
|
|
36
|
+
encodeRequest(request, context) {
|
|
37
|
+
if (!isTextRequest(request)) {
|
|
38
|
+
throw refuse('unsupported-modality', 'spec-claude-code-exec only encodes text requests.');
|
|
39
|
+
}
|
|
40
|
+
refuseWhatTheTurnCannotDo(request);
|
|
41
|
+
const args = withClaudeCodeSubscriptionPolicy([
|
|
42
|
+
'-p',
|
|
43
|
+
'--output-format',
|
|
44
|
+
'json',
|
|
45
|
+
'--max-turns',
|
|
46
|
+
'1',
|
|
47
|
+
'--tools',
|
|
48
|
+
'',
|
|
49
|
+
'--safe-mode',
|
|
50
|
+
'--no-session-persistence',
|
|
51
|
+
'--no-chrome',
|
|
52
|
+
'--disable-slash-commands'
|
|
53
|
+
]);
|
|
54
|
+
if (context.wireModelId && context.wireModelId !== 'claude') {
|
|
55
|
+
args.push('--model', context.wireModelId);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
path: '',
|
|
60
|
+
headers: {},
|
|
61
|
+
// The conversation is the child's stdin, never its argv: argv is visible to every process
|
|
62
|
+
// of the user (`ps`) and bounded by the OS, and a long history would fail with E2BIG.
|
|
63
|
+
body: {
|
|
64
|
+
args,
|
|
65
|
+
env: CLAUDE_CODE_SUBSCRIPTION_ENV,
|
|
66
|
+
stdin: new TextEncoder().encode(encodePrompt(request.messages)),
|
|
67
|
+
suppressStdout: false
|
|
68
|
+
},
|
|
69
|
+
streaming: false
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async *decodeResponse(chunks, request, context) {
|
|
73
|
+
const stdoutChunks = [];
|
|
74
|
+
let stdoutBytes = 0;
|
|
75
|
+
try {
|
|
76
|
+
for await (const chunk of chunks) {
|
|
77
|
+
if (chunk.kind === 'bytes') {
|
|
78
|
+
stdoutBytes += chunk.data.length;
|
|
79
|
+
if (stdoutBytes > MAX_CLAUDE_STDOUT_BYTES) {
|
|
80
|
+
throw new CapabilityError('Claude Code wrote more output than one turn accepts.', 'UNAVAILABLE', {
|
|
81
|
+
reason: 'invalid-response-body',
|
|
82
|
+
retryable: false,
|
|
83
|
+
details: { limit: 'stdout' }
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
stdoutChunks.push(chunk.data);
|
|
87
|
+
}
|
|
88
|
+
else if (chunk.kind === 'error') {
|
|
89
|
+
yield { kind: 'error', error: childFailure(chunk.error) };
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
else if (chunk.kind === 'end') {
|
|
93
|
+
const output = new TextDecoder().decode(concatAll(stdoutChunks)).trim();
|
|
94
|
+
const content = extractClaudeContent(output);
|
|
95
|
+
const result = {
|
|
96
|
+
id: `${context.providerId}.${context.variantId}.${Date.now()}`,
|
|
97
|
+
timestamp: new Date(),
|
|
98
|
+
content,
|
|
99
|
+
metadata: { modelVersion: context.wireModelId, finishReason: 'stop' }
|
|
100
|
+
};
|
|
101
|
+
yield textResultEvent(request, result);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (thrown) {
|
|
107
|
+
const failure = CaughtFailureSchema.parse(thrown);
|
|
108
|
+
if (!isCapabilityError(failure))
|
|
109
|
+
throw thrown;
|
|
110
|
+
yield { kind: 'error', error: failure };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Tools, images and the options the turn has no flag for are refused, never dropped: a caller that
|
|
116
|
+
* asked for a temperature or a tool must learn this route does not run it, not receive an answer
|
|
117
|
+
* produced without it.
|
|
118
|
+
*/
|
|
119
|
+
function refuseWhatTheTurnCannotDo(request) {
|
|
120
|
+
if (request.tools && request.tools.length > 0) {
|
|
121
|
+
throw refuse('unsupported-request', 'The Claude Code subscription turn runs no tools.', ['tools']);
|
|
122
|
+
}
|
|
123
|
+
const fields = UNHONOURED_FIELDS.filter((field) => request[field] !== undefined);
|
|
124
|
+
if (fields.length > 0) {
|
|
125
|
+
throw refuse('unsupported-request', 'The Claude Code subscription turn cannot honour these request options.', fields);
|
|
126
|
+
}
|
|
127
|
+
for (const message of request.messages) {
|
|
128
|
+
if (message.images && message.images.length > 0) {
|
|
129
|
+
throw refuse('unsupported-request', 'The Claude Code subscription turn takes no images.', ['images']);
|
|
130
|
+
}
|
|
131
|
+
if (message.role === 'tool' || (message.toolCalls && message.toolCalls.length > 0)) {
|
|
132
|
+
throw refuse('unsupported-request', 'The Claude Code subscription turn runs no tools.', ['toolCalls']);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* What a child's failure becomes. A cancellation or a deadline keeps its shape (the framework
|
|
138
|
+
* classifies those by it); anything else (the transport's message quotes the child's stderr) becomes
|
|
139
|
+
* a fixed message whose only carrier of child text is a bounded `cause`.
|
|
140
|
+
*/
|
|
141
|
+
function childFailure(error) {
|
|
142
|
+
const failure = CaughtFailureSchema.parse(error);
|
|
143
|
+
if (!(failure instanceof Error))
|
|
144
|
+
return refuse('invalid-response-body', 'Claude Code reported a non-error failure.');
|
|
145
|
+
if (isCapabilityError(failure))
|
|
146
|
+
return failure;
|
|
147
|
+
if (failure instanceof DOMException && (failure.name === 'AbortError' || failure.name === 'TimeoutError')) {
|
|
148
|
+
return failure;
|
|
149
|
+
}
|
|
150
|
+
return new CapabilityError('Claude Code exited without an answer.', 'UNAVAILABLE', {
|
|
151
|
+
reason: 'claude-code-failed',
|
|
152
|
+
retryable: false,
|
|
153
|
+
cause: providerTextCause(failure.message)
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/** The role delimiters of the prompt framing; content that spells one is escaped so it cannot close or open a turn. */
|
|
157
|
+
const ROLE_DELIMITER = /<(\/?)(system|user|assistant|tool)(\s*)>/gi;
|
|
158
|
+
function escapeDelimiters(content) {
|
|
159
|
+
return content.replace(ROLE_DELIMITER, '<$1$2$3>');
|
|
160
|
+
}
|
|
161
|
+
function encodePrompt(messages) {
|
|
162
|
+
return messages
|
|
163
|
+
.map((message) => `<${message.role}>\n${escapeDelimiters(message.content)}\n</${message.role}>`)
|
|
164
|
+
.join('\n\n');
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The assistant text of `claude -p --output-format json`. An answer the CLI flags as an error, one
|
|
168
|
+
* that is not JSON, and one with no text are failures: none is assistant content.
|
|
169
|
+
*/
|
|
170
|
+
function extractClaudeContent(stdout) {
|
|
171
|
+
if (!stdout)
|
|
172
|
+
throw emptyContent();
|
|
173
|
+
let decoded;
|
|
174
|
+
try {
|
|
175
|
+
decoded = JSON.parse(stdout);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
if (!(error instanceof SyntaxError))
|
|
179
|
+
throw error;
|
|
180
|
+
throw emptyContent();
|
|
181
|
+
}
|
|
182
|
+
const output = ClaudeOutputSchema.safeParse(decoded);
|
|
183
|
+
if (!output.success)
|
|
184
|
+
throw emptyContent();
|
|
185
|
+
if (output.data.is_error === true) {
|
|
186
|
+
throw new CapabilityError('Claude Code reported an error instead of an answer.', 'UNAVAILABLE', {
|
|
187
|
+
reason: 'claude-code-failed',
|
|
188
|
+
retryable: false,
|
|
189
|
+
cause: providerTextCause(output.data.result ?? '')
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
for (const value of [
|
|
193
|
+
output.data.result,
|
|
194
|
+
output.data.response,
|
|
195
|
+
output.data.content,
|
|
196
|
+
output.data.text
|
|
197
|
+
]) {
|
|
198
|
+
if (value?.trim())
|
|
199
|
+
return value.trim();
|
|
200
|
+
}
|
|
201
|
+
throw emptyContent();
|
|
202
|
+
}
|
|
203
|
+
function emptyContent() {
|
|
204
|
+
return new CapabilityError('Claude Code wrote no assistant content.', 'INTERNAL', {
|
|
205
|
+
reason: 'empty-assistant-content',
|
|
206
|
+
retryable: false
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
export default new ClaudeCodeExecSpec();
|
|
210
|
+
//# sourceMappingURL=claude-code-exec.spec.impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code-exec.spec.impl.js","sourceRoot":"","sources":["../../../../src/ai/specs/claude-code-exec/claude-code-exec.spec.impl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,M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eAAe,IAAI,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp-server.consumer.plugin.d.ts","sourceRoot":"","sources":["../../src/external/acp-server.consumer.plugin.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,wBAAwB,6CAc5B,CAAC;AAEH,eAAe,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Claude subscription ACP server as a `pm/resource-provider` asset (id =
|
|
3
|
+
* `acp/server`). The implementation loads lazily, on the first acp/server
|
|
4
|
+
* resource. The `pm/resource-provider` kind itself stays owned by
|
|
5
|
+
* `@vibesdotdev/pm`; this plugin only contributes the vendor descriptor and
|
|
6
|
+
* its consumer-scoped loader, so a host composes it next to pm's plugin.
|
|
7
|
+
*/
|
|
8
|
+
import { createRuntimeAsset, createRuntimePlugin, loader } from '@vibesdotdev/kernel';
|
|
9
|
+
import { RESOURCE_PROVIDER_KIND } from '@vibesdotdev/pm/resources/provider';
|
|
10
|
+
const descriptor = createRuntimeAsset({
|
|
11
|
+
kind: RESOURCE_PROVIDER_KIND,
|
|
12
|
+
id: 'acp/server',
|
|
13
|
+
name: 'ACP server',
|
|
14
|
+
description: 'A Claude subscription ACP server.'
|
|
15
|
+
});
|
|
16
|
+
// Hoisted: tsc 6.0.3 does not rewrite `.ts` specifiers inside `export default <expr>`.
|
|
17
|
+
const anthropicAcpServerPlugin = createRuntimePlugin({
|
|
18
|
+
id: 'integrations-anthropic/acp-server',
|
|
19
|
+
name: 'ACP server resource provider',
|
|
20
|
+
description: 'Claude subscription ACP server for the pm/resource-provider kind',
|
|
21
|
+
descriptors: [descriptor],
|
|
22
|
+
loaders: [
|
|
23
|
+
loader(descriptor.id, { kind: RESOURCE_PROVIDER_KIND, scope: 'consumer' }, async () => ({
|
|
24
|
+
impl: (await import("./acp-server.js")).acpServerProvider
|
|
25
|
+
}))
|
|
26
|
+
]
|
|
27
|
+
});
|
|
28
|
+
export default anthropicAcpServerPlugin;
|
|
29
|
+
//# sourceMappingURL=acp-server.consumer.plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp-server.consumer.plugin.js","sourceRoot":"","sources":["../../src/external/acp-server.consumer.plugin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAyB,MAAM,oCAAoC,CAAC;AAEnG,MAAM,UAAU,GAAG,kBAAkB,CAAC;IACrC,IAAI,EAAE,sBAAsB;IAC5B,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,mCAAmC;CAChD,CAAC,CAAC;AAEH,uFAAuF;AACvF,MAAM,wBAAwB,GAAG,mBAAmB,CAAC;IACpD,EAAE,EAAE,mCAAmC;IACvC,IAAI,EAAE,8BAA8B;IACpC,WAAW,EAAE,kEAAkE;IAC/E,WAAW,EAAE,CAAC,UAAU,CAAC;IACzB,OAAO,EAAE;QACR,MAAM,CACL,UAAU,CAAC,EAAE,EACb,EAAE,IAAI,EAAE,sBAAsB,EAAE,KAAK,EAAE,UAAU,EAAE,EACnD,KAAK,IAAkD,EAAE,CAAC,CAAC;YAC1D,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,iBAAiB;SACzD,CAAC,CACF;KACD;CACD,CAAC,CAAC;AAEH,eAAe,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP Server Resource Provider
|
|
3
|
+
*
|
|
4
|
+
* Manages lifecycle for an external ACP server process (today: `claude-code-acp`).
|
|
5
|
+
* This is process supervision only — the third-party child does not inherit a
|
|
6
|
+
* Vibes runtime. A Vibes-owned ACP runtime surface should be introduced only
|
|
7
|
+
* with a real host that consumes it.
|
|
8
|
+
*/
|
|
9
|
+
import * as z from 'zod/v4';
|
|
10
|
+
import type { ResourceProvider } from '@vibesdotdev/pm/resources/provider';
|
|
11
|
+
/** The provider's own config: a port (0 picks a free one) and the start timeout; anything else is the default. */
|
|
12
|
+
declare const AcpServerConfigSchema: z.ZodObject<{
|
|
13
|
+
port: z.ZodCatch<z.ZodNumber>;
|
|
14
|
+
timeout: z.ZodCatch<z.ZodNumber>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
type AcpServerConfig = z.infer<typeof AcpServerConfigSchema>;
|
|
17
|
+
export declare const acpServerProvider: ResourceProvider<AcpServerConfig>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=acp-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp-server.d.ts","sourceRoot":"","sources":["../../src/external/acp-server.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAI5B,OAAO,KAAK,EACX,gBAAgB,EAKhB,MAAM,oCAAoC,CAAC;AAa5C,kHAAkH;AAClH,QAAA,MAAM,qBAAqB;;;iBAGzB,CAAC;AACH,KAAK,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAoD7D,eAAO,MAAM,iBAAiB,EAAE,gBAAgB,CAAC,eAAe,CAkJ/D,CAAC"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP Server Resource Provider
|
|
3
|
+
*
|
|
4
|
+
* Manages lifecycle for an external ACP server process (today: `claude-code-acp`).
|
|
5
|
+
* This is process supervision only — the third-party child does not inherit a
|
|
6
|
+
* Vibes runtime. A Vibes-owned ACP runtime surface should be introduced only
|
|
7
|
+
* with a real host that consumes it.
|
|
8
|
+
*/
|
|
9
|
+
import * as z from 'zod/v4';
|
|
10
|
+
import { getRuntimeProcessService } from '@vibesdotdev/kernel/process';
|
|
11
|
+
import { getRuntimeSocketService } from '@vibesdotdev/kernel/socket';
|
|
12
|
+
import { ProviderPayloadSchema } from '@vibesdotdev/pm/schemas/resource';
|
|
13
|
+
import { spawnSupervised } from '@vibesdotdev/pm/utils/exec';
|
|
14
|
+
import { attempt } from '@vibesdotdev/pm/utils/attempt';
|
|
15
|
+
import { resolvePMToolEnv } from '@vibesdotdev/pm/helpers/process-env';
|
|
16
|
+
import { hasErrno, rethrowFailure } from '@vibesdotdev/pm/helpers/failure';
|
|
17
|
+
import { pollUntil } from '@vibesdotdev/pm/utils/bounded-wait';
|
|
18
|
+
/** The provider's own config: a port (0 picks a free one) and the start timeout; anything else is the default. */
|
|
19
|
+
const AcpServerConfigSchema = z.object({
|
|
20
|
+
port: z.number().catch(0),
|
|
21
|
+
timeout: z.number().catch(30000)
|
|
22
|
+
});
|
|
23
|
+
/** What a running server's resource state keeps in its metadata: the process and the port it answers on. */
|
|
24
|
+
const AcpStateMetadataSchema = z.object({
|
|
25
|
+
pid: z.number().int().positive().optional().catch(undefined),
|
|
26
|
+
port: z.number().int().positive().optional().catch(undefined)
|
|
27
|
+
});
|
|
28
|
+
/** A server's `acp/status` answer: whether it is authenticated. */
|
|
29
|
+
const AcpStatusAnswerSchema = z.object({ result: z.object({ authenticated: z.boolean().optional() }).optional() });
|
|
30
|
+
/** The one address a listening ephemeral probe socket reports. */
|
|
31
|
+
const BoundAddressSchema = z.object({ type: z.literal('tcp'), port: z.number().int().positive().max(65535) });
|
|
32
|
+
const STATUS_REQUEST_BODY = JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'acp/status' });
|
|
33
|
+
/**
|
|
34
|
+
* ACP Server Resource Provider
|
|
35
|
+
*/
|
|
36
|
+
/** A probe failure that means "nothing is answering yet": refused, reset, or its deadline. */
|
|
37
|
+
function isNotListening(failure) {
|
|
38
|
+
if (!(failure instanceof Error))
|
|
39
|
+
return false;
|
|
40
|
+
if (failure.name === 'TimeoutError' || failure.name === 'AbortError' || failure instanceof TypeError)
|
|
41
|
+
return true;
|
|
42
|
+
return hasErrno(failure, 'ECONNREFUSED') || hasErrno(failure, 'ECONNRESET') || hasErrno(failure, 'ConnectionRefused');
|
|
43
|
+
}
|
|
44
|
+
/** One `acp/status` request to the server on `port`: its response, or the failure that ended it. */
|
|
45
|
+
function probeStatus(port, timeoutMs) {
|
|
46
|
+
return attempt(() => fetch(`http://localhost:${port}/jsonrpc`, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: { 'Content-Type': 'application/json' },
|
|
49
|
+
body: STATUS_REQUEST_BODY,
|
|
50
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
/** The resource state of this provider's server: its process and port ride in `metadata`, which the store keeps. */
|
|
54
|
+
function serverState(config, status, fields = {}) {
|
|
55
|
+
const metadata = {};
|
|
56
|
+
if (fields.pid !== undefined)
|
|
57
|
+
metadata.pid = fields.pid;
|
|
58
|
+
if (fields.port !== undefined)
|
|
59
|
+
metadata.port = fields.port;
|
|
60
|
+
const state = { id: config.id, type: config.type, status, lastChecked: new Date(), metadata };
|
|
61
|
+
if (fields.error !== undefined)
|
|
62
|
+
state.error = fields.error;
|
|
63
|
+
return state;
|
|
64
|
+
}
|
|
65
|
+
export const acpServerProvider = {
|
|
66
|
+
type: 'acp',
|
|
67
|
+
subType: 'server',
|
|
68
|
+
validateConfig(config) {
|
|
69
|
+
return AcpServerConfigSchema.parse(config);
|
|
70
|
+
},
|
|
71
|
+
async setup(config, context) {
|
|
72
|
+
const acpConfig = this.validateConfig(config.config || {});
|
|
73
|
+
let actualPort = acpConfig.port;
|
|
74
|
+
// Find available port if needed
|
|
75
|
+
if (actualPort === 0) {
|
|
76
|
+
const sockets = await getRuntimeSocketService(context.runtime);
|
|
77
|
+
const listener = await sockets.listenTcp({ host: '127.0.0.1', port: 0 }, {
|
|
78
|
+
open(socket) { socket.destroy(); },
|
|
79
|
+
data(socket) { socket.destroy(); },
|
|
80
|
+
close() { }
|
|
81
|
+
});
|
|
82
|
+
try {
|
|
83
|
+
const address = BoundAddressSchema.safeParse(listener.endpoint);
|
|
84
|
+
if (!address.success) {
|
|
85
|
+
return { state: serverState(config, 'error', { error: 'Failed to bind to ephemeral port' }) };
|
|
86
|
+
}
|
|
87
|
+
actualPort = address.data.port;
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
await listener.stop();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Check if already running on this port. Nothing answering on the port
|
|
94
|
+
// means not running, so it is started below.
|
|
95
|
+
const running = await probeStatus(actualPort, 2000);
|
|
96
|
+
if (running.ok) {
|
|
97
|
+
if (running.value.ok)
|
|
98
|
+
return { state: serverState(config, 'ready', { port: actualPort }) };
|
|
99
|
+
}
|
|
100
|
+
else if (!isNotListening(running.failure)) {
|
|
101
|
+
rethrowFailure(running.failure);
|
|
102
|
+
}
|
|
103
|
+
// Spawn the third-party ACP server. It is not a Vibes runtime host.
|
|
104
|
+
// Its environment is the kernel's host set with PM's PATH repair; a
|
|
105
|
+
// credential reaches it only as a lease in its declaration (RC05).
|
|
106
|
+
const proc = await spawnSupervised(context.runtime, 'claude-code-acp', ['serve', '--port', String(actualPort)], {
|
|
107
|
+
env: await resolvePMToolEnv(context.runtime),
|
|
108
|
+
envMode: 'replace'
|
|
109
|
+
});
|
|
110
|
+
// Wait for the server to answer, bounded by the runtime lifecycle (RC07).
|
|
111
|
+
// Poll: the ACP server (owner) publishes no readiness event; a refused or
|
|
112
|
+
// failing probe is "not yet" (it is starting), and the deadline decides.
|
|
113
|
+
const answered = await pollUntil(context.runtime, async () => {
|
|
114
|
+
const probe = await probeStatus(actualPort, 1000);
|
|
115
|
+
if (probe.ok)
|
|
116
|
+
return probe.value.ok;
|
|
117
|
+
// Connection refused or probe deadline while the server starts: not yet.
|
|
118
|
+
if (isNotListening(probe.failure))
|
|
119
|
+
return false;
|
|
120
|
+
return rethrowFailure(probe.failure);
|
|
121
|
+
}, { timeoutMs: acpConfig.timeout, intervalMs: 100, reason: 'pm-acp-server-ready' });
|
|
122
|
+
if (answered) {
|
|
123
|
+
const pid = proc.pid ?? 0;
|
|
124
|
+
return {
|
|
125
|
+
state: serverState(config, 'ready', { pid, port: actualPort }),
|
|
126
|
+
metadata: { port: actualPort, pid }
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// Timeout - kill process and fail
|
|
130
|
+
await proc.kill();
|
|
131
|
+
return { state: serverState(config, 'error', { error: 'ACP server failed to start within timeout' }) };
|
|
132
|
+
},
|
|
133
|
+
async teardown(_id, state, context) {
|
|
134
|
+
const { pid } = AcpStateMetadataSchema.parse(state?.metadata ?? {});
|
|
135
|
+
if (!pid)
|
|
136
|
+
return;
|
|
137
|
+
const service = await getRuntimeProcessService(context.runtime);
|
|
138
|
+
const signalled = await attempt(() => service.signal(pid, 'SIGTERM'));
|
|
139
|
+
// Already gone (ESRCH) is the goal; any other failure propagates.
|
|
140
|
+
if (!signalled.ok && !hasErrno(signalled.failure, 'ESRCH'))
|
|
141
|
+
rethrowFailure(signalled.failure);
|
|
142
|
+
},
|
|
143
|
+
async status(_id) {
|
|
144
|
+
// Try common ports
|
|
145
|
+
const ports = [3100, 3101, 3102];
|
|
146
|
+
for (const port of ports) {
|
|
147
|
+
// Nothing answering on a port: try the next.
|
|
148
|
+
const probe = await probeStatus(port, 1000);
|
|
149
|
+
if (!probe.ok) {
|
|
150
|
+
if (!isNotListening(probe.failure))
|
|
151
|
+
rethrowFailure(probe.failure);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (!probe.value.ok)
|
|
155
|
+
continue;
|
|
156
|
+
const answer = ProviderPayloadSchema.safeParse(await probe.value.json());
|
|
157
|
+
const metadata = { port };
|
|
158
|
+
if (answer.success)
|
|
159
|
+
Object.assign(metadata, answer.data);
|
|
160
|
+
return { status: 'ready', metadata };
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
status: 'stopped'
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
async checkReady(_config, state) {
|
|
167
|
+
const { port } = AcpStateMetadataSchema.parse(state?.metadata ?? {});
|
|
168
|
+
if (!port) {
|
|
169
|
+
return {
|
|
170
|
+
ready: false,
|
|
171
|
+
reason: 'No port configured'
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const probe = await probeStatus(port, 2000);
|
|
175
|
+
if (probe.ok) {
|
|
176
|
+
if (probe.value.ok) {
|
|
177
|
+
const answer = AcpStatusAnswerSchema.safeParse(await probe.value.json());
|
|
178
|
+
if (answer.success && answer.data.result?.authenticated) {
|
|
179
|
+
return { ready: true };
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
ready: false,
|
|
183
|
+
reason: 'ACP server running but not authenticated'
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else if (!isNotListening(probe.failure)) {
|
|
188
|
+
// Server not responding yet is below; any other failure propagates.
|
|
189
|
+
rethrowFailure(probe.failure);
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
ready: false,
|
|
193
|
+
reason: 'ACP server not responding',
|
|
194
|
+
retryAfter: 1000
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
//# sourceMappingURL=acp-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp-server.js","sourceRoot":"","sources":["../../src/external/acp-server.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAQrE,OAAO,EACN,qBAAqB,EAIrB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAgB,MAAM,+BAA+B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EAAE,KAAK;gBACZ,MAAM,EAAE,oBAAoB;aAC5B,CAAC;QACH,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5C,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC;YACd,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;gBACpB,MAAM,MAAM,GAAG,qBAAqB,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;gBACzE,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC;oBACzD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;gBACxB,CAAC;gBACD,OAAO;oBACN,KAAK,EAAE,KAAK;oBACZ,MAAM,EAAE,0CAA0C;iBAClD,CAAC;YACH,CAAC;QACF,CAAC;aAAM,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3C,oEAAoE;YACpE,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO;YACN,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,2BAA2B;YACnC,UAAU,EAAE,IAAI;SAChB,CAAC;IACH,CAAC;CACD,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type ExternalHookAdapter, type ExternalHookEnvelope, type ExternalHookInvocation, type ExternalHookRenderResult } from '@vibesdotdev/external/hooks';
|
|
2
|
+
import type { HookEvent } from '@vibesdotdev/external';
|
|
3
|
+
/** Envelope trigger marking a Stop hook that Claude re-ran after the hook's own block. */
|
|
4
|
+
export declare const STOP_HOOK_ACTIVE_TRIGGER = "stop-hook-active";
|
|
5
|
+
export declare const claudeCodeHookAdapterDescriptor: {
|
|
6
|
+
id: string;
|
|
7
|
+
kind: "external/hook-adapter";
|
|
8
|
+
toolId: string;
|
|
9
|
+
nativeEventMap: Record<string, "context.beforeCompact" | "tool.before" | "prompt.submit" | "agent.stop" | "subagent.stop" | "tool.after" | "session.start" | "session.end" | "context.afterCompact" | "permission.request" | "notification">;
|
|
10
|
+
name?: string | undefined;
|
|
11
|
+
description?: string | undefined;
|
|
12
|
+
tags?: string[] | undefined;
|
|
13
|
+
hardware?: string[] | undefined;
|
|
14
|
+
enabled?: boolean | undefined;
|
|
15
|
+
priority?: number | undefined;
|
|
16
|
+
capabilityId?: string | undefined;
|
|
17
|
+
requiredContext?: string[] | undefined;
|
|
18
|
+
optionalContext?: string[] | undefined;
|
|
19
|
+
config?: unknown;
|
|
20
|
+
retention?: string | {
|
|
21
|
+
reason: string;
|
|
22
|
+
maxAgeDays?: number | undefined;
|
|
23
|
+
maxEntries?: number | undefined;
|
|
24
|
+
maxBytes?: number | undefined;
|
|
25
|
+
cascadeFrom?: string | undefined;
|
|
26
|
+
ageField?: string | undefined;
|
|
27
|
+
enforcedBy?: string | undefined;
|
|
28
|
+
} | undefined;
|
|
29
|
+
};
|
|
30
|
+
/** What the envelope retains of model-controlled text and values: bounded, so a hook never stores a megabyte a tool read. */
|
|
31
|
+
export declare const HOOK_ENVELOPE_LIMITS: {
|
|
32
|
+
readonly promptChars: 32768;
|
|
33
|
+
readonly toolInputChars: 32768;
|
|
34
|
+
readonly toolResponseChars: 65536;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Normalize one Claude Code hook payload. The payload's `cwd` names the
|
|
38
|
+
* workspace and `session_id` the session; a sparse payload takes them from the
|
|
39
|
+
* caller's `invocation`. With neither, the hook fails `INVALID_INPUT`
|
|
40
|
+
* (`hook-session-unnamed`, `hook-workspace-unnamed`): nothing guesses.
|
|
41
|
+
*/
|
|
42
|
+
export declare function normalizeClaudeCodeHook(event: HookEvent, raw: string, invocation: ExternalHookInvocation): ExternalHookEnvelope;
|
|
43
|
+
/** Claude Code stdout dialect. Cognition/context remains Framework-owned input here. */
|
|
44
|
+
export declare function renderClaudeCodeHook(result: ExternalHookRenderResult): string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* The adapter the hook host resolves. Its caller passes the hook invocation's
|
|
47
|
+
* own workspace and session (`ExternalHookInvocation`, never the serving
|
|
48
|
+
* host's), which a sparse payload falls back to.
|
|
49
|
+
*/
|
|
50
|
+
export declare const claudeCodeHookAdapter: ExternalHookAdapter;
|
|
51
|
+
//# sourceMappingURL=claude-code-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code-hooks.d.ts","sourceRoot":"","sources":["../../src/external/claude-code-hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAGN,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AA6BvD,0FAA0F;AAC1F,eAAO,MAAM,wBAAwB,qBAAqB,CAAC;AAI3D,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;CAQ1C,CAAC;AAWH,6HAA6H;AAC7H,eAAO,MAAM,oBAAoB;;;;CAIvB,CAAC;AAuFX;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,SAAS,EAChB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,sBAAsB,GAChC,oBAAoB,CAiFtB;AAED,wFAAwF;AACxF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,wBAAwB,GAAG,MAAM,GAAG,SAAS,CAyCzF;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,mBAGnC,CAAC"}
|