hankweave 0.5.7 → 0.6.2
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/README.md +12 -11
- package/dist/base-process-manager.d.ts +30 -0
- package/dist/budget.d.ts +315 -0
- package/dist/checkpoint-git.d.ts +98 -0
- package/dist/claude-agent-sdk-manager.d.ts +144 -0
- package/dist/claude-log-parser.d.ts +63 -0
- package/dist/claude-runtime-extractor.d.ts +73 -0
- package/dist/codex-runtime-extractor.d.ts +107 -0
- package/dist/codon-runner.d.ts +278 -0
- package/dist/config-validation/model-validator.d.ts +16 -0
- package/dist/config-validation/sentinel.schema.d.ts +6967 -0
- package/dist/config.d.ts +40815 -0
- package/dist/cost-tracker.d.ts +72 -0
- package/dist/execution-planner.d.ts +62 -0
- package/dist/execution-thread.d.ts +71 -0
- package/dist/exports/schemas.d.ts +9 -0
- package/dist/exports/schemas.js +1019 -0
- package/dist/exports/types.d.ts +15 -0
- package/dist/exports/types.js +60 -0
- package/dist/file-resolver.d.ts +33 -0
- package/dist/index.js +380 -293
- package/dist/index.js.map +33 -29
- package/dist/llm/llm-provider-registry.d.ts +207 -0
- package/dist/llm/models-dev-schema.d.ts +679 -0
- package/dist/llm/provider-config.d.ts +30 -0
- package/dist/prompt-builder.d.ts +75 -0
- package/dist/prompt-frontmatter.d.ts +61 -0
- package/dist/replay-process-manager.d.ts +82 -0
- package/dist/runtime-extractor-base.d.ts +120 -0
- package/dist/schemas/event-schemas.d.ts +8389 -0
- package/dist/schemas/websocket-log-schemas.d.ts +4502 -0
- package/dist/shim-process-manager.d.ts +98 -0
- package/dist/shim-runtime-extractor.d.ts +51 -0
- package/dist/shims/codex/README.md +129 -0
- package/dist/shims/codex/THIRDPARTY.md +18 -0
- package/dist/shims/codex/VERSION +1 -0
- package/dist/shims/codex/common/package.json +24 -0
- package/dist/shims/codex/index.js +1154 -970
- package/dist/shims/codex/package.json +46 -0
- package/dist/shims/codex/tsup.config.ts +16 -0
- package/dist/shims/gemini/README.md +59 -0
- package/dist/shims/gemini/THIRDPARTY.md +32 -0
- package/dist/shims/gemini/VERSION +1 -0
- package/dist/shims/gemini/common/package.json +24 -0
- package/dist/shims/gemini/index.js +1359 -30
- package/dist/shims/gemini/package.json +37 -0
- package/dist/shims/opencode/README.md +82 -0
- package/dist/shims/opencode/THIRDPARTY.md +32 -0
- package/dist/shims/opencode/VERSION +1 -0
- package/dist/shims/opencode/common/package.json +24 -0
- package/dist/shims/opencode/index.js +1476 -0
- package/dist/shims/opencode/package.json +38 -0
- package/dist/shims/pi/README.md +87 -0
- package/dist/shims/pi/THIRDPARTY.md +24 -0
- package/dist/shims/pi/VERSION +1 -0
- package/dist/shims/pi/common/package.json +24 -0
- package/dist/shims/pi/index.js +249832 -0
- package/dist/shims/pi/package.json +53 -0
- package/dist/state-manager.d.ts +161 -0
- package/dist/state-transition-guards.d.ts +37 -0
- package/dist/telemetry/telemetry-types.d.ts +206 -0
- package/dist/typed-event-emitter.d.ts +57 -0
- package/dist/types/branded-types.d.ts +15 -0
- package/dist/types/budget-types.d.ts +82 -0
- package/dist/types/claude-session-schema.d.ts +2430 -0
- package/dist/types/error-types.d.ts +44 -0
- package/dist/types/input-ai-types.d.ts +1070 -0
- package/dist/types/llm-call-types.d.ts +3829 -0
- package/dist/types/sentinel-types.d.ts +66 -0
- package/dist/types/state-types.d.ts +1099 -0
- package/dist/types/tool-types.d.ts +86 -0
- package/dist/types/types.d.ts +367 -0
- package/dist/types/websocket-log-types.d.ts +7 -0
- package/dist/utils.d.ts +452 -0
- package/package.json +15 -2
- package/schemas/hank.schema.json +158 -3
- package/schemas/hankweave.schema.json +17 -1
- package/shims/codex/index.js +0 -1583
- package/shims/gemini/index.js +0 -31
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { PromptFrontmatter } from "./prompt-frontmatter.js";
|
|
2
|
+
import type { Codon } from "./types/types.js";
|
|
3
|
+
import type { Logger } from "./utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Handles all prompt-related functionality for process managers.
|
|
6
|
+
* Builds system prompts, user prompts, parses frontmatter, and applies template replacements.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PromptBuilder {
|
|
9
|
+
private agentRootPath;
|
|
10
|
+
private logger;
|
|
11
|
+
private globalSystemPrompt?;
|
|
12
|
+
private lastFrontmatter?;
|
|
13
|
+
constructor(agentRootPath: string, logger: Logger, globalSystemPrompt?: string | null | undefined);
|
|
14
|
+
/**
|
|
15
|
+
* Build system prompt from global prompt and/or codon-specific prompt.
|
|
16
|
+
* Global prompt is prepended, then codon-specific prompt follows.
|
|
17
|
+
*
|
|
18
|
+
* @returns Combined system prompt with template replacements applied, or null if no prompts configured
|
|
19
|
+
*/
|
|
20
|
+
buildSystemPrompt(codon: Codon): string | null;
|
|
21
|
+
/**
|
|
22
|
+
* Build prompt content from file or text.
|
|
23
|
+
* Parses and strips frontmatter from markdown files.
|
|
24
|
+
* Stores frontmatter metadata for later retrieval via getLastFrontmatter().
|
|
25
|
+
*
|
|
26
|
+
* @returns Prompt content with template replacements applied and optional frontmatter metadata
|
|
27
|
+
*/
|
|
28
|
+
buildPromptContent(codon: Codon): {
|
|
29
|
+
content: string;
|
|
30
|
+
frontmatter?: PromptFrontmatter;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Get frontmatter metadata from the last built prompt.
|
|
34
|
+
* Returns undefined if no frontmatter was present or no prompt has been built yet.
|
|
35
|
+
*/
|
|
36
|
+
getLastFrontmatter(): PromptFrontmatter | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Process prompt variables in a string (for exhaustion/extension prompts).
|
|
39
|
+
* Replaces template variables: <%PROJECT_DIR%>, <%EXECUTION_DIR%>, <%DATA_DIR%>
|
|
40
|
+
* Also strips HTML comments.
|
|
41
|
+
*
|
|
42
|
+
* @param prompt - Raw prompt text with template variables
|
|
43
|
+
* @returns Prompt with variables substituted and comments stripped
|
|
44
|
+
*/
|
|
45
|
+
processPromptVariables(prompt: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Build prompt content for execution, handling both normal and exhaustion modes.
|
|
48
|
+
* This consolidates the prompt choosing logic used by both managers.
|
|
49
|
+
*
|
|
50
|
+
* @param codon - Codon configuration
|
|
51
|
+
* @param exhaustionPrompt - Optional exhaustion prompt (activates exhaustion mode)
|
|
52
|
+
* @returns Processed prompt content ready for execution
|
|
53
|
+
*/
|
|
54
|
+
buildPromptForExecution(codon: Codon, exhaustionPrompt?: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Apply template variable replacements to content.
|
|
57
|
+
* All workspace variables resolve to agentRootPath (where agents work).
|
|
58
|
+
*
|
|
59
|
+
* Supports:
|
|
60
|
+
* - <%AGENT_ROOT%> - Canonical variable for agent workspace (recommended)
|
|
61
|
+
* - <%PROJECT_DIR%> - Silent alias for AGENT_ROOT
|
|
62
|
+
* - <%EXECUTION_DIR%> - Silent alias for AGENT_ROOT
|
|
63
|
+
* - <%DATA_DIR%> - Data directory (agentRootPath/read_only_data_source)
|
|
64
|
+
*/
|
|
65
|
+
private applyTemplateReplacements;
|
|
66
|
+
/**
|
|
67
|
+
* Strip HTML comments from content.
|
|
68
|
+
* HTML comments (<!-- ... -->) are removed before sending to the LLM.
|
|
69
|
+
* Also consumes a trailing newline to avoid blank lines accumulating.
|
|
70
|
+
*
|
|
71
|
+
* @param content - Content with potential HTML comments
|
|
72
|
+
* @returns Content with comments stripped
|
|
73
|
+
*/
|
|
74
|
+
private stripHtmlComments;
|
|
75
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple frontmatter parser for prompt markdown files.
|
|
3
|
+
*
|
|
4
|
+
* Frontmatter is ONLY for metadata/labeling (not configuration).
|
|
5
|
+
* Allowed fields: name, description, tags, version, author
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ---
|
|
9
|
+
* name: Code Analyzer
|
|
10
|
+
* description: Analyzes code for patterns
|
|
11
|
+
* tags: [analysis, code-review]
|
|
12
|
+
* version: 1.0.0
|
|
13
|
+
* author: Team Name
|
|
14
|
+
* ---
|
|
15
|
+
*/
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
/**
|
|
18
|
+
* Schema for allowed frontmatter fields.
|
|
19
|
+
* Strict validation - rejects unknown fields.
|
|
20
|
+
*/
|
|
21
|
+
export declare const promptFrontmatterSchema: z.ZodObject<{
|
|
22
|
+
name: z.ZodOptional<z.ZodString>;
|
|
23
|
+
description: z.ZodOptional<z.ZodString>;
|
|
24
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
25
|
+
version: z.ZodOptional<z.ZodString>;
|
|
26
|
+
author: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, "strict", z.ZodTypeAny, {
|
|
28
|
+
name?: string | undefined;
|
|
29
|
+
description?: string | undefined;
|
|
30
|
+
tags?: string[] | undefined;
|
|
31
|
+
version?: string | undefined;
|
|
32
|
+
author?: string | undefined;
|
|
33
|
+
}, {
|
|
34
|
+
name?: string | undefined;
|
|
35
|
+
description?: string | undefined;
|
|
36
|
+
tags?: string[] | undefined;
|
|
37
|
+
version?: string | undefined;
|
|
38
|
+
author?: string | undefined;
|
|
39
|
+
}>;
|
|
40
|
+
export type PromptFrontmatter = z.infer<typeof promptFrontmatterSchema>;
|
|
41
|
+
export interface ParsedPrompt {
|
|
42
|
+
/** The prompt content without frontmatter */
|
|
43
|
+
content: string;
|
|
44
|
+
/** Parsed frontmatter metadata (undefined if no frontmatter) */
|
|
45
|
+
frontmatter?: PromptFrontmatter;
|
|
46
|
+
/** Whether the file had frontmatter */
|
|
47
|
+
hasFrontmatter: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parse frontmatter from markdown content.
|
|
51
|
+
* Returns the content without frontmatter and the parsed metadata.
|
|
52
|
+
*
|
|
53
|
+
* @param rawContent - Raw markdown content (may include frontmatter)
|
|
54
|
+
* @returns Parsed prompt with content and optional frontmatter
|
|
55
|
+
* @throws Error if frontmatter has invalid fields
|
|
56
|
+
*/
|
|
57
|
+
export declare function parsePromptFrontmatter(rawContent: string): ParsedPrompt;
|
|
58
|
+
/**
|
|
59
|
+
* Format frontmatter metadata for display.
|
|
60
|
+
*/
|
|
61
|
+
export declare function formatFrontmatterForDisplay(frontmatter: PromptFrontmatter): string;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { BaseProcessManager } from "./base-process-manager.js";
|
|
2
|
+
import type { ClaudeLogParser } from "./claude-log-parser.js";
|
|
3
|
+
import type { Codon } from "./types/types.js";
|
|
4
|
+
import type { Logger } from "./utils.js";
|
|
5
|
+
/**
|
|
6
|
+
* ReplayProcessManager replays a previously recorded JSONL log file
|
|
7
|
+
* instead of making real LLM API calls.
|
|
8
|
+
*
|
|
9
|
+
* It implements the same interface as ClaudeAgentSDKManager and ShimProcessManager,
|
|
10
|
+
* writing source JSONL lines progressively to the target log file so that
|
|
11
|
+
* ClaudeLogParser can pick them up via its normal polling mechanism.
|
|
12
|
+
*
|
|
13
|
+
* For extensions (context exhaustion), tracks position across multiple spawn() calls,
|
|
14
|
+
* writing lines from after the previous result message to the next result message.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ReplayProcessManager extends BaseProcessManager {
|
|
17
|
+
private executionPath;
|
|
18
|
+
private sourceLogPath;
|
|
19
|
+
private replaySpeed;
|
|
20
|
+
private logStream;
|
|
21
|
+
private syntheticPid;
|
|
22
|
+
private running;
|
|
23
|
+
private finished;
|
|
24
|
+
private replayTimer;
|
|
25
|
+
private sourceLines;
|
|
26
|
+
private currentLineIndex;
|
|
27
|
+
constructor(executionPath: string, logger: Logger, logParser: ClaudeLogParser, sourceLogPath: string, replaySpeed?: number);
|
|
28
|
+
/** Replay doesn't use prompt frontmatter */
|
|
29
|
+
get promptFrontmatter(): undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Spawn a replay session for the given codon.
|
|
32
|
+
* Reads from the source JSONL log and writes lines progressively to the target log file.
|
|
33
|
+
*
|
|
34
|
+
* Matches the ClaudeAgentSDKManager.spawn() signature.
|
|
35
|
+
*/
|
|
36
|
+
spawn(codon: Codon, _sessionToResume: string | null, options?: {
|
|
37
|
+
logPath?: string;
|
|
38
|
+
exhaustionPrompt?: string;
|
|
39
|
+
}): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Write lines one at a time with delays between them.
|
|
42
|
+
* Uses timestamps from log entries for realistic timing when available,
|
|
43
|
+
* falling back to fixed replaySpeed for old logs without timestamps.
|
|
44
|
+
* Stops at result messages and emits exit.
|
|
45
|
+
*/
|
|
46
|
+
private writeNextLine;
|
|
47
|
+
/**
|
|
48
|
+
* Peek at the timestamp of the next unwritten line without advancing the index.
|
|
49
|
+
*/
|
|
50
|
+
private peekNextTimestamp;
|
|
51
|
+
/**
|
|
52
|
+
* Calculate the delay before writing the next line.
|
|
53
|
+
* Uses timestamps for realistic timing when available,
|
|
54
|
+
* falls back to fixed replaySpeed for old logs without timestamps.
|
|
55
|
+
* Caps maximum delay to avoid long waits from tool executions.
|
|
56
|
+
*/
|
|
57
|
+
private calculateDelay;
|
|
58
|
+
/**
|
|
59
|
+
* Finish a replay session: flush log parser, clean up, emit exit.
|
|
60
|
+
*/
|
|
61
|
+
private finishReplay;
|
|
62
|
+
/**
|
|
63
|
+
* Kill the replay session.
|
|
64
|
+
*/
|
|
65
|
+
kill(_signal?: NodeJS.Signals): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Force-kill the replay session.
|
|
68
|
+
*/
|
|
69
|
+
forceKill(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Check if replay is in progress.
|
|
72
|
+
*/
|
|
73
|
+
isRunning(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Get synthetic PID.
|
|
76
|
+
*/
|
|
77
|
+
getPid(): number | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Close log stream explicitly.
|
|
80
|
+
*/
|
|
81
|
+
closeLogStream(): Promise<void>;
|
|
82
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Extractor Base
|
|
3
|
+
*
|
|
4
|
+
* Shared utilities for extracting embedded runtime files (binaries, SDKs, shims)
|
|
5
|
+
* from compiled executables. This module provides common functionality used by:
|
|
6
|
+
* - codex-runtime-extractor.ts (Codex binary extraction)
|
|
7
|
+
* - claude-runtime-extractor.ts (Claude SDK files extraction)
|
|
8
|
+
* - shim-runtime-extractor.ts (Shim files extraction)
|
|
9
|
+
*
|
|
10
|
+
* Key Concepts:
|
|
11
|
+
* - Embedded files: Files bundled into the executable using Bun's --embed flag
|
|
12
|
+
* - Extraction: Writing embedded files to disk for use as subprocesses
|
|
13
|
+
* - Versioned cache: Extracted files stored in versioned directories (e.g., ~/.hankweave/component/version/)
|
|
14
|
+
* - Marker files: Indicate successful extraction and version tracking
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for a single file to extract
|
|
18
|
+
*/
|
|
19
|
+
export interface FileToExtract {
|
|
20
|
+
/** Path to the embedded file (e.g., "node_modules/package/file.js") */
|
|
21
|
+
embeddedPath: string;
|
|
22
|
+
/** Path where the file should be extracted (relative to extraction directory) */
|
|
23
|
+
outputPath: string;
|
|
24
|
+
/** Whether extraction should fail if this file is missing */
|
|
25
|
+
required: boolean;
|
|
26
|
+
/** Whether to make the file executable (Unix only) */
|
|
27
|
+
makeExecutable?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Configuration for extracting a component's files
|
|
31
|
+
*/
|
|
32
|
+
export interface ExtractionConfig {
|
|
33
|
+
/** Human-readable component name (e.g., "Codex", "Claude SDK") */
|
|
34
|
+
componentName: string;
|
|
35
|
+
/** Version string for cache directory naming */
|
|
36
|
+
version: string;
|
|
37
|
+
/** Optional base path prefix for embedded files */
|
|
38
|
+
embeddedBasePath?: string;
|
|
39
|
+
/** List of files to extract */
|
|
40
|
+
filesToExtract: FileToExtract[];
|
|
41
|
+
/** Custom marker file name (defaults to ".extraction-complete") */
|
|
42
|
+
markerFileName?: string;
|
|
43
|
+
/** Optional function to validate extraction was successful */
|
|
44
|
+
validateExtraction?: (extractionDir: string) => boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Result of an extraction operation
|
|
48
|
+
*/
|
|
49
|
+
export interface ExtractionResult {
|
|
50
|
+
/** Directory where files were extracted */
|
|
51
|
+
extractionDir: string;
|
|
52
|
+
/** Paths of successfully extracted files */
|
|
53
|
+
extractedFiles: string[];
|
|
54
|
+
/** Files that failed to extract (with error messages) */
|
|
55
|
+
failedFiles: Array<{
|
|
56
|
+
path: string;
|
|
57
|
+
error: string;
|
|
58
|
+
}>;
|
|
59
|
+
/** Whether cached files were used (no extraction needed) */
|
|
60
|
+
usedCache: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get the Bun virtual filesystem prefix for the current platform.
|
|
64
|
+
* - Unix: /$bunfs/root
|
|
65
|
+
* - Windows: X:/~BUN/root (where X is the drive letter from process.argv[1])
|
|
66
|
+
*/
|
|
67
|
+
export declare function getBunVfsPrefix(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Read an embedded file from Bun.embeddedFiles.
|
|
70
|
+
*
|
|
71
|
+
* First tries to find the file in Bun.embeddedFiles (the recommended way),
|
|
72
|
+
* then falls back to Bun.file() with various path formats.
|
|
73
|
+
*
|
|
74
|
+
* Throws if the file doesn't exist or can't be read.
|
|
75
|
+
*/
|
|
76
|
+
export declare function readEmbeddedFile(embeddedPath: string): Promise<ArrayBuffer>;
|
|
77
|
+
/**
|
|
78
|
+
* Compute a hash of file content for verification.
|
|
79
|
+
* Returns first 12 characters of MD5 hash for compact display.
|
|
80
|
+
*/
|
|
81
|
+
export declare function computeFileHash(content: Buffer | string): string;
|
|
82
|
+
/**
|
|
83
|
+
* Get the base extraction directory (usually ~/.hankweave/).
|
|
84
|
+
* Respects HANKWEAVE_CACHE_DIR environment variable.
|
|
85
|
+
*/
|
|
86
|
+
export declare function getExtractionBaseDir(): string;
|
|
87
|
+
/**
|
|
88
|
+
* Get the extraction directory for a specific component and version.
|
|
89
|
+
*
|
|
90
|
+
* @param componentName - Component identifier (e.g., "codex-sdk", "claude-sdk", "shims")
|
|
91
|
+
* @param version - Version string for directory naming
|
|
92
|
+
* @returns Full path to extraction directory (e.g., ~/.hankweave/codex-sdk/0.87.0/)
|
|
93
|
+
*/
|
|
94
|
+
export declare function getComponentExtractionDir(componentName: string, version: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* Check if extraction is needed based on marker file and version.
|
|
97
|
+
*
|
|
98
|
+
* @param extractionDir - Directory where files would be extracted
|
|
99
|
+
* @param expectedVersion - Version string to compare against marker
|
|
100
|
+
* @param markerFileName - Name of marker file (defaults to ".extraction-complete")
|
|
101
|
+
* @param requiredFiles - Optional list of files that must exist
|
|
102
|
+
* @returns true if extraction is needed, false if cache is valid
|
|
103
|
+
*/
|
|
104
|
+
export declare function needsExtraction(extractionDir: string, expectedVersion: string, markerFileName?: string, requiredFiles?: string[]): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Extract embedded files to disk based on configuration.
|
|
107
|
+
*
|
|
108
|
+
* This is the main extraction engine that:
|
|
109
|
+
* 1. Creates extraction directory
|
|
110
|
+
* 2. Optionally lists all embedded files for debugging
|
|
111
|
+
* 3. Extracts each configured file
|
|
112
|
+
* 4. Sets executable permissions where needed
|
|
113
|
+
* 5. Writes version marker file
|
|
114
|
+
*
|
|
115
|
+
* @param config - Extraction configuration
|
|
116
|
+
* @param debugListFiles - Whether to log all embedded files (default: true)
|
|
117
|
+
* @returns Extraction result with paths and status
|
|
118
|
+
* @throws Error if required files fail to extract
|
|
119
|
+
*/
|
|
120
|
+
export declare function extractFiles(config: ExtractionConfig, debugListFiles?: boolean): Promise<ExtractionResult>;
|