@vibefield/puppeteer-adapter-claude 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/dist/detection.d.ts +78 -0
- package/dist/detection.d.ts.map +1 -0
- package/dist/detection.js +167 -0
- package/dist/detection.js.map +1 -0
- package/dist/driver.d.ts +145 -0
- package/dist/driver.d.ts.map +1 -0
- package/dist/driver.js +840 -0
- package/dist/driver.js.map +1 -0
- package/dist/generated/detection-surface.d.ts +30 -0
- package/dist/generated/detection-surface.d.ts.map +1 -0
- package/dist/generated/detection-surface.js +34 -0
- package/dist/generated/detection-surface.js.map +1 -0
- package/dist/generated/registry.d.ts +45 -0
- package/dist/generated/registry.d.ts.map +1 -0
- package/dist/generated/registry.js +287 -0
- package/dist/generated/registry.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/launch/hook-switches.d.ts +32 -0
- package/dist/launch/hook-switches.d.ts.map +1 -0
- package/dist/launch/hook-switches.js +56 -0
- package/dist/launch/hook-switches.js.map +1 -0
- package/dist/launch/invocation-grammar.d.ts +196 -0
- package/dist/launch/invocation-grammar.d.ts.map +1 -0
- package/dist/launch/invocation-grammar.js +857 -0
- package/dist/launch/invocation-grammar.js.map +1 -0
- package/dist/launch/native-invocation.d.ts +42 -0
- package/dist/launch/native-invocation.d.ts.map +1 -0
- package/dist/launch/native-invocation.js +130 -0
- package/dist/launch/native-invocation.js.map +1 -0
- package/dist/launch/prepare.d.ts +137 -0
- package/dist/launch/prepare.d.ts.map +1 -0
- package/dist/launch/prepare.js +317 -0
- package/dist/launch/prepare.js.map +1 -0
- package/dist/launch/settings.d.ts +63 -0
- package/dist/launch/settings.d.ts.map +1 -0
- package/dist/launch/settings.js +94 -0
- package/dist/launch/settings.js.map +1 -0
- package/dist/normalization/adapter.d.ts +3 -0
- package/dist/normalization/adapter.d.ts.map +1 -0
- package/dist/normalization/adapter.js +4 -0
- package/dist/normalization/adapter.js.map +1 -0
- package/dist/normalization/compaction.d.ts +4 -0
- package/dist/normalization/compaction.d.ts.map +1 -0
- package/dist/normalization/compaction.js +7 -0
- package/dist/normalization/compaction.js.map +1 -0
- package/dist/normalization/context-window.d.ts +3 -0
- package/dist/normalization/context-window.d.ts.map +1 -0
- package/dist/normalization/context-window.js +4 -0
- package/dist/normalization/context-window.js.map +1 -0
- package/dist/normalization/conversation.d.ts +3 -0
- package/dist/normalization/conversation.d.ts.map +1 -0
- package/dist/normalization/conversation.js +4 -0
- package/dist/normalization/conversation.js.map +1 -0
- package/dist/normalization/delegation.d.ts +4 -0
- package/dist/normalization/delegation.d.ts.map +1 -0
- package/dist/normalization/delegation.js +7 -0
- package/dist/normalization/delegation.js.map +1 -0
- package/dist/normalization/effort.d.ts +8 -0
- package/dist/normalization/effort.d.ts.map +1 -0
- package/dist/normalization/effort.js +16 -0
- package/dist/normalization/effort.js.map +1 -0
- package/dist/normalization/environment.d.ts +5 -0
- package/dist/normalization/environment.d.ts.map +1 -0
- package/dist/normalization/environment.js +10 -0
- package/dist/normalization/environment.js.map +1 -0
- package/dist/normalization/index.d.ts +20 -0
- package/dist/normalization/index.d.ts.map +1 -0
- package/dist/normalization/index.js +20 -0
- package/dist/normalization/index.js.map +1 -0
- package/dist/normalization/interaction.d.ts +38 -0
- package/dist/normalization/interaction.d.ts.map +1 -0
- package/dist/normalization/interaction.js +60 -0
- package/dist/normalization/interaction.js.map +1 -0
- package/dist/normalization/mode.d.ts +11 -0
- package/dist/normalization/mode.d.ts.map +1 -0
- package/dist/normalization/mode.js +37 -0
- package/dist/normalization/mode.js.map +1 -0
- package/dist/normalization/model.d.ts +5 -0
- package/dist/normalization/model.d.ts.map +1 -0
- package/dist/normalization/model.js +7 -0
- package/dist/normalization/model.js.map +1 -0
- package/dist/normalization/monitor-capabilities.d.ts +4 -0
- package/dist/normalization/monitor-capabilities.d.ts.map +1 -0
- package/dist/normalization/monitor-capabilities.js +121 -0
- package/dist/normalization/monitor-capabilities.js.map +1 -0
- package/dist/normalization/monitor.d.ts +46 -0
- package/dist/normalization/monitor.d.ts.map +1 -0
- package/dist/normalization/monitor.js +332 -0
- package/dist/normalization/monitor.js.map +1 -0
- package/dist/normalization/notification.d.ts +4 -0
- package/dist/normalization/notification.d.ts.map +1 -0
- package/dist/normalization/notification.js +9 -0
- package/dist/normalization/notification.js.map +1 -0
- package/dist/normalization/pipeline.d.ts +56 -0
- package/dist/normalization/pipeline.d.ts.map +1 -0
- package/dist/normalization/pipeline.js +472 -0
- package/dist/normalization/pipeline.js.map +1 -0
- package/dist/normalization/session.d.ts +6 -0
- package/dist/normalization/session.d.ts.map +1 -0
- package/dist/normalization/session.js +17 -0
- package/dist/normalization/session.js.map +1 -0
- package/dist/normalization/tool.d.ts +8 -0
- package/dist/normalization/tool.d.ts.map +1 -0
- package/dist/normalization/tool.js +64 -0
- package/dist/normalization/tool.js.map +1 -0
- package/dist/normalization/turn.d.ts +6 -0
- package/dist/normalization/turn.d.ts.map +1 -0
- package/dist/normalization/turn.js +15 -0
- package/dist/normalization/turn.js.map +1 -0
- package/dist/normalization/types.d.ts +47 -0
- package/dist/normalization/types.d.ts.map +1 -0
- package/dist/normalization/types.js +2 -0
- package/dist/normalization/types.js.map +1 -0
- package/dist/normalization/wire.d.ts +10 -0
- package/dist/normalization/wire.d.ts.map +1 -0
- package/dist/normalization/wire.js +75 -0
- package/dist/normalization/wire.js.map +1 -0
- package/dist/normalization/workspace.d.ts +5 -0
- package/dist/normalization/workspace.d.ts.map +1 -0
- package/dist/normalization/workspace.js +68 -0
- package/dist/normalization/workspace.js.map +1 -0
- package/dist/observation/hook-bridge.d.ts +72 -0
- package/dist/observation/hook-bridge.d.ts.map +1 -0
- package/dist/observation/hook-bridge.js +250 -0
- package/dist/observation/hook-bridge.js.map +1 -0
- package/dist/observation/otel/actor.d.ts +14 -0
- package/dist/observation/otel/actor.d.ts.map +1 -0
- package/dist/observation/otel/actor.js +44 -0
- package/dist/observation/otel/actor.js.map +1 -0
- package/dist/observation/otel/capability.d.ts +4 -0
- package/dist/observation/otel/capability.d.ts.map +1 -0
- package/dist/observation/otel/capability.js +24 -0
- package/dist/observation/otel/capability.js.map +1 -0
- package/dist/observation/otel/index.d.ts +6 -0
- package/dist/observation/otel/index.d.ts.map +1 -0
- package/dist/observation/otel/index.js +6 -0
- package/dist/observation/otel/index.js.map +1 -0
- package/dist/observation/otel/model.d.ts +9 -0
- package/dist/observation/otel/model.d.ts.map +1 -0
- package/dist/observation/otel/model.js +16 -0
- package/dist/observation/otel/model.js.map +1 -0
- package/dist/observation/otel/usage.d.ts +16 -0
- package/dist/observation/otel/usage.d.ts.map +1 -0
- package/dist/observation/otel/usage.js +75 -0
- package/dist/observation/otel/usage.js.map +1 -0
- package/dist/observation/otel/wire.d.ts +15 -0
- package/dist/observation/otel/wire.d.ts.map +1 -0
- package/dist/observation/otel/wire.js +147 -0
- package/dist/observation/otel/wire.js.map +1 -0
- package/dist/observation/semantic-provider.d.ts +45 -0
- package/dist/observation/semantic-provider.d.ts.map +1 -0
- package/dist/observation/semantic-provider.js +8 -0
- package/dist/observation/semantic-provider.js.map +1 -0
- package/dist/observation/status-channel.d.ts +70 -0
- package/dist/observation/status-channel.d.ts.map +1 -0
- package/dist/observation/status-channel.js +268 -0
- package/dist/observation/status-channel.js.map +1 -0
- package/dist/observation/transcript/conversation.d.ts +6 -0
- package/dist/observation/transcript/conversation.d.ts.map +1 -0
- package/dist/observation/transcript/conversation.js +170 -0
- package/dist/observation/transcript/conversation.js.map +1 -0
- package/dist/observation/transcript/index.d.ts +5 -0
- package/dist/observation/transcript/index.d.ts.map +1 -0
- package/dist/observation/transcript/index.js +5 -0
- package/dist/observation/transcript/index.js.map +1 -0
- package/dist/observation/transcript/provider.d.ts +7 -0
- package/dist/observation/transcript/provider.d.ts.map +1 -0
- package/dist/observation/transcript/provider.js +132 -0
- package/dist/observation/transcript/provider.js.map +1 -0
- package/dist/observation/transcript/services/jsonl-reader.d.ts +12 -0
- package/dist/observation/transcript/services/jsonl-reader.d.ts.map +1 -0
- package/dist/observation/transcript/services/jsonl-reader.js +140 -0
- package/dist/observation/transcript/services/jsonl-reader.js.map +1 -0
- package/dist/observation/transcript/services/yield.d.ts +3 -0
- package/dist/observation/transcript/services/yield.d.ts.map +1 -0
- package/dist/observation/transcript/services/yield.js +15 -0
- package/dist/observation/transcript/services/yield.js.map +1 -0
- package/dist/observation/transcript/wire.d.ts +26 -0
- package/dist/observation/transcript/wire.d.ts.map +1 -0
- package/dist/observation/transcript/wire.js +89 -0
- package/dist/observation/transcript/wire.js.map +1 -0
- package/dist/services/account-usage.d.ts +86 -0
- package/dist/services/account-usage.d.ts.map +1 -0
- package/dist/services/account-usage.js +813 -0
- package/dist/services/account-usage.js.map +1 -0
- package/dist/services/distribution.d.ts +64 -0
- package/dist/services/distribution.d.ts.map +1 -0
- package/dist/services/distribution.js +255 -0
- package/dist/services/distribution.js.map +1 -0
- package/dist/services/event-source.d.ts +29 -0
- package/dist/services/event-source.d.ts.map +1 -0
- package/dist/services/event-source.js +38 -0
- package/dist/services/event-source.js.map +1 -0
- package/dist/services/extensions.d.ts +46 -0
- package/dist/services/extensions.d.ts.map +1 -0
- package/dist/services/extensions.js +1263 -0
- package/dist/services/extensions.js.map +1 -0
- package/dist/services/models.d.ts +6 -0
- package/dist/services/models.d.ts.map +1 -0
- package/dist/services/models.js +90 -0
- package/dist/services/models.js.map +1 -0
- package/dist/services/profiles.d.ts +48 -0
- package/dist/services/profiles.d.ts.map +1 -0
- package/dist/services/profiles.js +176 -0
- package/dist/services/profiles.js.map +1 -0
- package/dist/services/prompt.d.ts +39 -0
- package/dist/services/prompt.d.ts.map +1 -0
- package/dist/services/prompt.js +107 -0
- package/dist/services/prompt.js.map +1 -0
- package/package.json +46 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 James Yong
|
|
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.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude executable detection and capability probe (DESIGN §10, §16.2 steps
|
|
3
|
+
* 1–3). Capability-probe, don't assume: we read `claude --version` and
|
|
4
|
+
* `claude --help` and report which launch flags the native driver depends on.
|
|
5
|
+
*
|
|
6
|
+
* Raw detection never throws for missing flags: it reports warnings + false in
|
|
7
|
+
* `flags`. Launch preflight is stricter and throws a typed capability error only
|
|
8
|
+
* when the concrete recipe needs one of those missing flags. The exec function
|
|
9
|
+
* is injected so unit tests run against fakes; the real binary is exercised
|
|
10
|
+
* only by the opt-in integration test gated on CLAUDE_NATIVE_TUI_LIVE.
|
|
11
|
+
*/
|
|
12
|
+
/** Native version flag from the generated detection surface; reused by the distribution service. */
|
|
13
|
+
export declare const CLAUDE_VERSION_FLAG: string;
|
|
14
|
+
/** Injected process runner; the default wraps node:child_process execFile. */
|
|
15
|
+
export type ClaudeExec = (file: string, args: string[]) => Promise<{
|
|
16
|
+
stdout: string;
|
|
17
|
+
}>;
|
|
18
|
+
export interface ClaudeFlagSupport {
|
|
19
|
+
sessionId: boolean;
|
|
20
|
+
settings: boolean;
|
|
21
|
+
settingSources: boolean;
|
|
22
|
+
name: boolean;
|
|
23
|
+
permissionMode: boolean;
|
|
24
|
+
resume: boolean;
|
|
25
|
+
model: boolean;
|
|
26
|
+
effort: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface ClaudeDetection {
|
|
29
|
+
/** The resolved command (an absolute path, or a bare name left to PATH). */
|
|
30
|
+
executable: string;
|
|
31
|
+
/** Parsed `x.y.z` from `--version`; undefined when it could not be read. */
|
|
32
|
+
version?: string | undefined;
|
|
33
|
+
flags: ClaudeFlagSupport;
|
|
34
|
+
/** Non-fatal capability gaps (missing flags, unreadable version). */
|
|
35
|
+
warnings: string[];
|
|
36
|
+
}
|
|
37
|
+
export interface DetectClaudeOptions {
|
|
38
|
+
executable?: string | undefined;
|
|
39
|
+
exec?: ClaudeExec | undefined;
|
|
40
|
+
}
|
|
41
|
+
export interface ClaudeLaunchRequirements {
|
|
42
|
+
/** Fresh sessions need the native UUID join contract. */
|
|
43
|
+
freshSession: boolean;
|
|
44
|
+
/** The adapter will add `--resume`; caller-owned resume picker argv stays caller-owned. */
|
|
45
|
+
resume?: boolean | undefined;
|
|
46
|
+
title?: boolean | undefined;
|
|
47
|
+
model?: boolean | undefined;
|
|
48
|
+
effort?: boolean | undefined;
|
|
49
|
+
settingSources?: boolean | undefined;
|
|
50
|
+
}
|
|
51
|
+
export interface PreflightClaudeLaunchOptions extends ClaudeLaunchRequirements {
|
|
52
|
+
executable?: string;
|
|
53
|
+
}
|
|
54
|
+
export type ClaudeLaunchCapability = keyof ClaudeFlagSupport;
|
|
55
|
+
/** A launch recipe cannot work against the detected executable's advertised surface. */
|
|
56
|
+
export declare class ClaudeCapabilityError extends Error {
|
|
57
|
+
readonly detection: ClaudeDetection;
|
|
58
|
+
readonly missingFlags: readonly ClaudeLaunchCapability[];
|
|
59
|
+
readonly code: "CLAUDE_CAPABILITY_MISSING";
|
|
60
|
+
constructor(detection: ClaudeDetection, missingFlags: readonly ClaudeLaunchCapability[]);
|
|
61
|
+
}
|
|
62
|
+
export declare const defaultClaudeExec: ClaudeExec;
|
|
63
|
+
/** `<semver> (Claude Code)` → `<semver>`; undefined when no semver is present. */
|
|
64
|
+
export declare function parseClaudeVersion(stdout: string): string | undefined;
|
|
65
|
+
/** Resolution order: explicit option → `PUPPETEER_CLAUDE_BIN` → PATH lookup of `claude`. */
|
|
66
|
+
export declare function resolveClaudeExecutable(explicit?: string, environment?: NodeJS.ProcessEnv): string;
|
|
67
|
+
export declare function detectClaude(options?: DetectClaudeOptions): Promise<ClaudeDetection>;
|
|
68
|
+
export declare function requiredClaudeLaunchCapabilities(requirements: ClaudeLaunchRequirements): ClaudeLaunchCapability[];
|
|
69
|
+
export declare function assertClaudeLaunchCapabilities(detection: ClaudeDetection, requirements: ClaudeLaunchRequirements): void;
|
|
70
|
+
export type ClaudeLaunchPreflight = (options: PreflightClaudeLaunchOptions) => Promise<ClaudeDetection>;
|
|
71
|
+
/**
|
|
72
|
+
* Build a process-lifetime preflight. Detection is cached per resolved executable,
|
|
73
|
+
* while each launch still checks only the flags its concrete recipe will use.
|
|
74
|
+
*/
|
|
75
|
+
export declare function createClaudeLaunchPreflight(exec?: ClaudeExec): ClaudeLaunchPreflight;
|
|
76
|
+
/** Shared cached preflight for built-in runtime providers. */
|
|
77
|
+
export declare const preflightClaudeLaunch: ClaudeLaunchPreflight;
|
|
78
|
+
//# sourceMappingURL=detection.d.ts.map
|
|
@@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167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude executable detection and capability probe (DESIGN §10, §16.2 steps
|
|
3
|
+
* 1–3). Capability-probe, don't assume: we read `claude --version` and
|
|
4
|
+
* `claude --help` and report which launch flags the native driver depends on.
|
|
5
|
+
*
|
|
6
|
+
* Raw detection never throws for missing flags: it reports warnings + false in
|
|
7
|
+
* `flags`. Launch preflight is stricter and throws a typed capability error only
|
|
8
|
+
* when the concrete recipe needs one of those missing flags. The exec function
|
|
9
|
+
* is injected so unit tests run against fakes; the real binary is exercised
|
|
10
|
+
* only by the opt-in integration test gated on CLAUDE_NATIVE_TUI_LIVE.
|
|
11
|
+
*/
|
|
12
|
+
import { execFile } from 'node:child_process';
|
|
13
|
+
import { promisify } from 'node:util';
|
|
14
|
+
import { CLAUDE_DETECTION_SURFACE } from './generated/detection-surface.js';
|
|
15
|
+
const surface = CLAUDE_DETECTION_SURFACE;
|
|
16
|
+
const versionPattern = new RegExp(surface.versionPattern);
|
|
17
|
+
const advertisedFlags = {
|
|
18
|
+
sessionId: surface.probedFlags.sessionId,
|
|
19
|
+
settings: surface.probedFlags.settings,
|
|
20
|
+
settingSources: surface.probedFlags.settingSources,
|
|
21
|
+
name: surface.probedFlags.name,
|
|
22
|
+
permissionMode: surface.probedFlags.permissionMode,
|
|
23
|
+
resume: surface.launchFlags.resume,
|
|
24
|
+
model: surface.launchFlags.model,
|
|
25
|
+
effort: surface.launchFlags.effort,
|
|
26
|
+
};
|
|
27
|
+
const flags = Object.fromEntries(Object.entries(advertisedFlags).map(([key, value]) => [
|
|
28
|
+
key,
|
|
29
|
+
value
|
|
30
|
+
.split(',')
|
|
31
|
+
.map((flag) => flag.trim())
|
|
32
|
+
.filter(Boolean),
|
|
33
|
+
]));
|
|
34
|
+
/** Native version flag from the generated detection surface; reused by the distribution service. */
|
|
35
|
+
export const CLAUDE_VERSION_FLAG = surface.versionFlag;
|
|
36
|
+
/** A launch recipe cannot work against the detected executable's advertised surface. */
|
|
37
|
+
export class ClaudeCapabilityError extends Error {
|
|
38
|
+
detection;
|
|
39
|
+
missingFlags;
|
|
40
|
+
code = 'CLAUDE_CAPABILITY_MISSING';
|
|
41
|
+
constructor(detection, missingFlags) {
|
|
42
|
+
const labels = missingFlags.map((flag) => flags[flag].join('/')).join(', ');
|
|
43
|
+
super(`Claude executable ${detection.executable} does not advertise required launch flags: ${labels}`);
|
|
44
|
+
this.detection = detection;
|
|
45
|
+
this.missingFlags = missingFlags;
|
|
46
|
+
this.name = 'ClaudeCapabilityError';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const execFileAsync = promisify(execFile);
|
|
50
|
+
const SCRIPT_EXECUTABLE = /\.(mjs|cjs|js|ts)$/;
|
|
51
|
+
export const defaultClaudeExec = async (file, args) => {
|
|
52
|
+
// Adapter/Imposter development commonly supplies a JavaScript entry point.
|
|
53
|
+
// Match launch preparation by running scripts under Node; Electron resolves
|
|
54
|
+
// `node` from PATH rather than accidentally entering Electron-as-Node.
|
|
55
|
+
const isScript = SCRIPT_EXECUTABLE.test(file);
|
|
56
|
+
const command = isScript ? (process.versions.electron ? 'node' : process.execPath) : file;
|
|
57
|
+
const commandArgs = isScript ? [file, ...args] : args;
|
|
58
|
+
const { stdout } = await execFileAsync(command, commandArgs, {
|
|
59
|
+
timeout: 10_000,
|
|
60
|
+
maxBuffer: 1024 * 1024,
|
|
61
|
+
encoding: 'utf8',
|
|
62
|
+
});
|
|
63
|
+
return { stdout };
|
|
64
|
+
};
|
|
65
|
+
function errMessage(err) {
|
|
66
|
+
return err instanceof Error ? err.message : String(err);
|
|
67
|
+
}
|
|
68
|
+
/** `<semver> (Claude Code)` → `<semver>`; undefined when no semver is present. */
|
|
69
|
+
export function parseClaudeVersion(stdout) {
|
|
70
|
+
return stdout.match(versionPattern)?.[1];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Match a flag as a standalone token. Help text lists flags whitespace- or
|
|
74
|
+
* comma-delimited (`-n, --name`), so a bare `includes` would false-positive
|
|
75
|
+
* (`-n` inside `--session-id` need not, but `--settings` inside `--settings-x`
|
|
76
|
+
* would). Bound the match on both sides.
|
|
77
|
+
*/
|
|
78
|
+
function helpHasFlag(help, flag) {
|
|
79
|
+
const escaped = flag.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
80
|
+
return new RegExp(`(^|[\\s,('"\`])${escaped}([\\s,)='"\`]|$)`, 'm').test(help);
|
|
81
|
+
}
|
|
82
|
+
/** Resolution order: explicit option → `PUPPETEER_CLAUDE_BIN` → PATH lookup of `claude`. */
|
|
83
|
+
export function resolveClaudeExecutable(explicit, environment = process.env) {
|
|
84
|
+
return explicit ?? environment[surface.envVar] ?? surface.executables[0] ?? 'claude';
|
|
85
|
+
}
|
|
86
|
+
export async function detectClaude(options = {}) {
|
|
87
|
+
const exec = options.exec ?? defaultClaudeExec;
|
|
88
|
+
const executable = resolveClaudeExecutable(options.executable);
|
|
89
|
+
const warnings = [];
|
|
90
|
+
let version;
|
|
91
|
+
try {
|
|
92
|
+
const { stdout } = await exec(executable, [surface.versionFlag]);
|
|
93
|
+
version = parseClaudeVersion(stdout);
|
|
94
|
+
if (!version) {
|
|
95
|
+
warnings.push(`could not parse version from \`${executable} ${surface.versionFlag}\`: ${stdout.trim()}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
warnings.push(`\`${executable} ${surface.versionFlag}\` failed: ${errMessage(err)}`);
|
|
100
|
+
}
|
|
101
|
+
let help = '';
|
|
102
|
+
try {
|
|
103
|
+
help = (await exec(executable, [surface.helpFlag])).stdout;
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
warnings.push(`\`${executable} ${surface.helpFlag}\` failed: ${errMessage(err)}`);
|
|
107
|
+
}
|
|
108
|
+
const supported = {
|
|
109
|
+
sessionId: flags.sessionId.some((flag) => helpHasFlag(help, flag)),
|
|
110
|
+
settings: flags.settings.some((flag) => helpHasFlag(help, flag)),
|
|
111
|
+
settingSources: flags.settingSources.some((flag) => helpHasFlag(help, flag)),
|
|
112
|
+
name: flags.name.some((flag) => helpHasFlag(help, flag)),
|
|
113
|
+
permissionMode: flags.permissionMode.some((flag) => helpHasFlag(help, flag)),
|
|
114
|
+
resume: flags.resume.some((flag) => helpHasFlag(help, flag)),
|
|
115
|
+
model: flags.model.some((flag) => helpHasFlag(help, flag)),
|
|
116
|
+
effort: flags.effort.some((flag) => helpHasFlag(help, flag)),
|
|
117
|
+
};
|
|
118
|
+
for (const key of Object.keys(supported)) {
|
|
119
|
+
if (!supported[key]) {
|
|
120
|
+
const label = flags[key].join('/');
|
|
121
|
+
warnings.push(`\`${executable} ${surface.helpFlag}\` does not advertise ${label}; native driver capability degraded`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { executable, version, flags: supported, warnings };
|
|
125
|
+
}
|
|
126
|
+
export function requiredClaudeLaunchCapabilities(requirements) {
|
|
127
|
+
const required = ['settings', 'permissionMode'];
|
|
128
|
+
if (requirements.freshSession)
|
|
129
|
+
required.push('sessionId');
|
|
130
|
+
if (requirements.resume)
|
|
131
|
+
required.push('resume');
|
|
132
|
+
if (requirements.title)
|
|
133
|
+
required.push('name');
|
|
134
|
+
if (requirements.model)
|
|
135
|
+
required.push('model');
|
|
136
|
+
if (requirements.effort)
|
|
137
|
+
required.push('effort');
|
|
138
|
+
if (requirements.settingSources)
|
|
139
|
+
required.push('settingSources');
|
|
140
|
+
return required;
|
|
141
|
+
}
|
|
142
|
+
export function assertClaudeLaunchCapabilities(detection, requirements) {
|
|
143
|
+
const missing = requiredClaudeLaunchCapabilities(requirements).filter((flag) => !detection.flags[flag]);
|
|
144
|
+
if (missing.length > 0)
|
|
145
|
+
throw new ClaudeCapabilityError(detection, missing);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Build a process-lifetime preflight. Detection is cached per resolved executable,
|
|
149
|
+
* while each launch still checks only the flags its concrete recipe will use.
|
|
150
|
+
*/
|
|
151
|
+
export function createClaudeLaunchPreflight(exec = defaultClaudeExec) {
|
|
152
|
+
const detections = new Map();
|
|
153
|
+
return async (options) => {
|
|
154
|
+
const executable = resolveClaudeExecutable(options.executable);
|
|
155
|
+
let detection = detections.get(executable);
|
|
156
|
+
if (!detection) {
|
|
157
|
+
detection = detectClaude({ executable, exec });
|
|
158
|
+
detections.set(executable, detection);
|
|
159
|
+
}
|
|
160
|
+
const resolved = await detection;
|
|
161
|
+
assertClaudeLaunchCapabilities(resolved, options);
|
|
162
|
+
return resolved;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Shared cached preflight for built-in runtime providers. */
|
|
166
|
+
export const preflightClaudeLaunch = createClaudeLaunchPreflight();
|
|
167
|
+
//# sourceMappingURL=detection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detection.js","sourceRoot":"","sources":["../src/detection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAe5E,MAAM,OAAO,GAAG,wBAAuD,CAAC;AACxE,MAAM,cAAc,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;AAC1D,MAAM,eAAe,GAA4C;IAC/D,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,SAAS;IACxC,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,QAAQ;IACtC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,cAAc;IAClD,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI;IAC9B,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,cAAc;IAClD,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,MAAM;IAClC,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,K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;AAID;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAAmB,iBAAiB;IAC9E,MAAM,UAAU,GAAG,IAAI,GAAG,EAAoC,CAAC;IAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,MAAM,UAAU,GAAG,uBAAuB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC/D,IAAI,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,SAAS,GAAG,YAAY,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;YAC/C,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QACxC,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC;QACjC,8BAA8B,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAClD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC;AAED,8DAA8D;AAC9D,MAAM,CAAC,MAAM,qBAAqB,GAAG,2BAA2B,EAAE,CAAC"}
|
package/dist/driver.d.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude session driver — the composition layer (DESIGN §11, §16).
|
|
3
|
+
*
|
|
4
|
+
* Runs HUB-SIDE (Electron main / future daemon), never in the pty-host: the
|
|
5
|
+
* host stays Claude-agnostic. The driver owns observation and control only;
|
|
6
|
+
* PROCESS lifecycle (spawn/terminate) belongs to the host behind the injected
|
|
7
|
+
* ports:
|
|
8
|
+
*
|
|
9
|
+
* prepare (settings + UUID join contract)
|
|
10
|
+
* → ports.spawn (the host carries the hook token in its explicit env grant)
|
|
11
|
+
* → hook bridge (loopback HTTP; the ONLY session it accepts is ours)
|
|
12
|
+
* → category normalizers → candidate event source → runtime ingress
|
|
13
|
+
* → live transcript provider (lazy: attached at the
|
|
14
|
+
* first hook payload that hands us transcript_path)
|
|
15
|
+
* → authenticated OTLP logs (settled request usage, when available)
|
|
16
|
+
* → prompt injector (uses ports.automate; confirmation and
|
|
17
|
+
* permission gating wired from the normalized event stream)
|
|
18
|
+
*
|
|
19
|
+
* Observation level (DESIGN §19.2) is reported honestly: 'terminal-only'
|
|
20
|
+
* until the first hook arrives, 'native-hooks' after.
|
|
21
|
+
*/
|
|
22
|
+
import { type AgentAdapterBinding, type BoundIngress, type HostIngress, type TerminalAutomationOperation, type TerminalAutomationResult } from '@vibefield/puppeteer-core';
|
|
23
|
+
import { type HookBridge, type HookBridgeOptions } from './observation/hook-bridge.js';
|
|
24
|
+
import { type ClaudeHookDiagnostic } from './normalization/index.js';
|
|
25
|
+
import { type PrepareClaudeSessionOptions, type PreparedClaudeSession } from './launch/prepare.js';
|
|
26
|
+
import type { SemanticObservationProvider } from './observation/semantic-provider.js';
|
|
27
|
+
export interface ClaudeSessionPorts {
|
|
28
|
+
/** Spawn the prepared command; resolves with the host's session id for writes. */
|
|
29
|
+
spawn(prepared: PreparedClaudeSession): Promise<{
|
|
30
|
+
runtimeSessionId: string;
|
|
31
|
+
}>;
|
|
32
|
+
/** Ordered semantic automation; never attaches a view or claims layout. */
|
|
33
|
+
automate(runtimeSessionId: string, operation: TerminalAutomationOperation): Promise<TerminalAutomationResult>;
|
|
34
|
+
}
|
|
35
|
+
export interface CreateClaudeSessionOptions {
|
|
36
|
+
cwd: string;
|
|
37
|
+
ports: ClaudeSessionPorts;
|
|
38
|
+
title?: string | undefined;
|
|
39
|
+
executable?: string | undefined;
|
|
40
|
+
/** Adapter-normalized launch environment; runtime consumers do not configure this directly. */
|
|
41
|
+
env?: Record<string, string> | undefined;
|
|
42
|
+
/** `default` when absent; `null` names none, and no configured mode is published (a typed launch that gave none). */
|
|
43
|
+
permissionMode?: string | null | undefined;
|
|
44
|
+
/** Model alias or full model id passed through to Claude Code. */
|
|
45
|
+
model?: string | undefined;
|
|
46
|
+
/** Claude Code binary version detected before launch, when available. */
|
|
47
|
+
providerVersion?: string | undefined;
|
|
48
|
+
/** Open-ended effort intent passed through to Claude Code. */
|
|
49
|
+
effort?: string | undefined;
|
|
50
|
+
/** Native settings layers loaded by Claude and considered for status-line delegation. */
|
|
51
|
+
settingSources?: readonly import('./observation/status-channel.js').ClaudeSettingSource[] | undefined;
|
|
52
|
+
/** Claude user configuration root when the launching environment relocates it. */
|
|
53
|
+
configDir?: string | undefined;
|
|
54
|
+
/** Opt into Claude FileChanged observation with its native filename matcher syntax. */
|
|
55
|
+
fileChangeMatcher?: string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Resume an existing session by id (native `--resume`; the session keeps its
|
|
58
|
+
* transcript and id—packages/surface/vendors/claude/findings.md §6). Omit to start fresh.
|
|
59
|
+
*/
|
|
60
|
+
resume?: string | undefined;
|
|
61
|
+
/** Preserve Claude's native resume picker/continue selection after launch. */
|
|
62
|
+
resumeInvocation?: string[] | undefined;
|
|
63
|
+
/** Observer fallback cadence; hook envelopes are the primary poll signal. */
|
|
64
|
+
transcriptPollIntervalMs?: number | undefined;
|
|
65
|
+
/** Non-blocking reports for malformed known hooks retained as native evidence. */
|
|
66
|
+
onDiagnostic?: ((diagnostic: ClaudeHookDiagnostic) => void) | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Stable ingress (core `HostIngress`): pin the hook bridge's port and token
|
|
69
|
+
* and learn what was bound before the process launches, so a host that
|
|
70
|
+
* outlives its own process can re-attach (`attachClaudeTuiSession`).
|
|
71
|
+
*/
|
|
72
|
+
ingress?: HostIngress | undefined;
|
|
73
|
+
/** Injectable bridge factory for deterministic transport-failure tests. */
|
|
74
|
+
hookBridgeFactory?: ((options: HookBridgeOptions) => HookBridge) | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Explicit fault injection for native canaries. After the selected accepted
|
|
77
|
+
* hook, close only the observation bridge while leaving Claude and its
|
|
78
|
+
* semantic transcript observer alive. Never set this for product sessions.
|
|
79
|
+
*/
|
|
80
|
+
hookRailFaultInjection?: ClaudeHookRailFaultInjection | undefined;
|
|
81
|
+
/** Injectable durable observer; defaults to live transcript updates. */
|
|
82
|
+
semanticProviderFactory?: (() => SemanticObservationProvider) | undefined;
|
|
83
|
+
/** Enable authenticated Claude OTLP request-completion logs. Defaults to true when no exporter conflict exists. */
|
|
84
|
+
observeOtlpUsage?: boolean | undefined;
|
|
85
|
+
/** Install and consume Claude's child status channel. Defaults to true for direct adapter callers. */
|
|
86
|
+
observeSubagentStatus?: boolean | undefined;
|
|
87
|
+
}
|
|
88
|
+
export interface ClaudeHookRailFaultInjection {
|
|
89
|
+
afterHookEvent: string;
|
|
90
|
+
occurrence?: number | undefined;
|
|
91
|
+
reason?: string | undefined;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The core adapter handle (sessionId is the shared native correlation UUID)
|
|
95
|
+
* plus Claude-specific transcript extras.
|
|
96
|
+
*/
|
|
97
|
+
export interface ClaudeSession extends AgentAdapterBinding {
|
|
98
|
+
/** Absolute path to this session's transcript JSONL (handed to us by hooks). */
|
|
99
|
+
transcriptPath(): string | undefined;
|
|
100
|
+
/** Force a transcript delta parse now (tests, explicit refresh). */
|
|
101
|
+
pollTranscript(): Promise<void>;
|
|
102
|
+
}
|
|
103
|
+
export interface PrepareClaudeTuiSessionOptions extends Omit<CreateClaudeSessionOptions, 'ports'>, Pick<PrepareClaudeSessionOptions, 'carriedArgs' | 'prompt' | 'home' | 'readsNoSettingsFiles' | 'refuseHooksOff'> {
|
|
104
|
+
/** Route semantic automation to a terminal after the preparation is adopted. */
|
|
105
|
+
automate(runtimeSessionId: string, operation: TerminalAutomationOperation): Promise<TerminalAutomationResult>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Bind to a Claude Code process that is ALREADY RUNNING in a host terminal —
|
|
109
|
+
* the restart half of stable ingress. The process was launched against a hook
|
|
110
|
+
* bridge on `ingress.port` with `ingress.token` (its settings and env carry
|
|
111
|
+
* both), so a listener rebound on exactly that ingress receives the hooks,
|
|
112
|
+
* status lines and telemetry it keeps posting; its durable transcript is found
|
|
113
|
+
* by the session id under the config root and tailed from the start. Nothing
|
|
114
|
+
* is launched; the terminal is adopted as-is.
|
|
115
|
+
*/
|
|
116
|
+
export interface AttachClaudeTuiSessionOptions extends Pick<CreateClaudeSessionOptions, 'cwd' | 'env' | 'permissionMode' | 'model' | 'effort' | 'providerVersion' | 'configDir' | 'transcriptPollIntervalMs' | 'onDiagnostic' | 'hookBridgeFactory' | 'semanticProviderFactory' | 'observeOtlpUsage' | 'observeSubagentStatus'> {
|
|
117
|
+
/** The native session id the running process announced. */
|
|
118
|
+
sessionId: string;
|
|
119
|
+
/** The host's id for the terminal the process is running in. */
|
|
120
|
+
runtimeSessionId: string;
|
|
121
|
+
/** The ingress the process was launched against — rebound as-is. */
|
|
122
|
+
ingress: BoundIngress;
|
|
123
|
+
/** Route semantic automation to the adopted terminal. */
|
|
124
|
+
automate(runtimeSessionId: string, operation: TerminalAutomationOperation): Promise<TerminalAutomationResult>;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A live Claude hook bridge plus an authoritative launch recipe that has not
|
|
128
|
+
* yet been bound to a host terminal. Call `adopt` before executing `launch` so
|
|
129
|
+
* the runtime is subscribed before Claude can emit its first hook.
|
|
130
|
+
*/
|
|
131
|
+
export interface PreparedClaudeTuiSession {
|
|
132
|
+
readonly sessionId: string;
|
|
133
|
+
readonly launch: PreparedClaudeSession;
|
|
134
|
+
adopt(runtimeSessionId: string): Promise<ClaudeSession>;
|
|
135
|
+
dispose(): Promise<void>;
|
|
136
|
+
}
|
|
137
|
+
export declare function prepareClaudeTuiSession(options: PrepareClaudeTuiSessionOptions): Promise<PreparedClaudeTuiSession>;
|
|
138
|
+
/**
|
|
139
|
+
* Bind to a running Claude Code process (see {@link AttachClaudeTuiSessionOptions}).
|
|
140
|
+
* Fails — before anything is adopted — when the pinned port cannot be bound:
|
|
141
|
+
* the host then knows the ingress is lost and resumes the continuation instead.
|
|
142
|
+
*/
|
|
143
|
+
export declare function attachClaudeTuiSession(options: AttachClaudeTuiSessionOptions): Promise<ClaudeSession>;
|
|
144
|
+
export declare function createClaudeSession(options: CreateClaudeSessionOptions): Promise<ClaudeSession>;
|
|
145
|
+
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,WAAW,EAEhB,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAE9B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAoB,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACzG,OAAO,EAAwB,KAAK,oBAAoB,EAA0B,MAAM,0BAA0B,CAAC;AACnH,OAAO,EAKL,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAC;AAgB7B,OAAO,KAAK,EAGV,2BAA2B,EAC5B,MAAM,oCAAoC,CAAC;AAmD5C,MAAM,WAAW,kBAAkB;IACjC,kFAAkF;IAClF,KAAK,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAAC;QAAE,gBAAgB,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9E,2EAA2E;IAC3E,QAAQ,CAAC,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,2BAA2B,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;CAC/G;AAED,MAAM,WAAW,0BAA0B;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,kBAAkB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,+FAA+F;IAC/F,GAAG,CAAC,EAAE,M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