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,98 @@
|
|
|
1
|
+
import { BaseProcessManager } from "./base-process-manager.js";
|
|
2
|
+
import type { ClaudeLogParser } from "./claude-log-parser.js";
|
|
3
|
+
import type { Codon, ShimSelfTestResult } from "./types/types.js";
|
|
4
|
+
import { type Logger } from "./utils.js";
|
|
5
|
+
/**
|
|
6
|
+
* Manages shim subprocess lifecycle, including spawning, monitoring, and cleanup.
|
|
7
|
+
* Handles log stream creation and process argument building.
|
|
8
|
+
* Works with any shim that supports the standardized argument interface.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ShimProcessManager extends BaseProcessManager {
|
|
11
|
+
private executionPath;
|
|
12
|
+
private agentRootPath;
|
|
13
|
+
private anthropicBaseUrl?;
|
|
14
|
+
private globalSystemPrompt?;
|
|
15
|
+
private defaultShimIdleTimeout?;
|
|
16
|
+
private process;
|
|
17
|
+
private logStream;
|
|
18
|
+
private stdoutReader;
|
|
19
|
+
private killed;
|
|
20
|
+
private promptBuilder;
|
|
21
|
+
constructor(executionPath: string, agentRootPath: string, logger: Logger, logParser: ClaudeLogParser, anthropicBaseUrl?: string | undefined, globalSystemPrompt?: string | null | undefined, defaultShimIdleTimeout?: number | undefined);
|
|
22
|
+
/** Frontmatter metadata from the prompt file (if any) */
|
|
23
|
+
get promptFrontmatter(): import("./prompt-frontmatter.js").PromptFrontmatter | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Spawn a shim process for the given codon configuration.
|
|
26
|
+
* Sets up logging, environment, and process monitoring.
|
|
27
|
+
*
|
|
28
|
+
* This unified method handles both normal codon execution and exhaustion extensions.
|
|
29
|
+
* From the shim's perspective, both are identical: resume a session with a new prompt.
|
|
30
|
+
* The difference is only where the prompt comes from.
|
|
31
|
+
*
|
|
32
|
+
* @param command - Command to execute (e.g., ["claude"] or ["bun", "run", "shims/gemini/dist/index.mjs"])
|
|
33
|
+
* @param codon - Codon configuration (not Loop - loops must be expanded first)
|
|
34
|
+
* @param sessionToResume - Session ID to resume (if any)
|
|
35
|
+
* @param options - Optional spawn configuration
|
|
36
|
+
* @param options.logPath - Custom log file path (defaults to .hankweave/logs/)
|
|
37
|
+
* @param options.exhaustionPrompt - If provided, activates exhaustion mode: uses this prompt
|
|
38
|
+
* instead of codon config, appends to log.
|
|
39
|
+
*/
|
|
40
|
+
spawn(command: string[], codon: Codon, sessionToResume: string | null, options?: {
|
|
41
|
+
logPath?: string;
|
|
42
|
+
exhaustionPrompt?: string;
|
|
43
|
+
}): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Build environment variables for the shim process.
|
|
46
|
+
*/
|
|
47
|
+
private buildEnvironment;
|
|
48
|
+
/**
|
|
49
|
+
* Build command line arguments for shim.
|
|
50
|
+
* Only includes arguments supported by all shims.
|
|
51
|
+
*
|
|
52
|
+
* @param codon - Codon configuration
|
|
53
|
+
* @param previousSessionId - Session ID to resume (if any)
|
|
54
|
+
* @param isExhaustionMode - True if this is an extension (exhaustion mode)
|
|
55
|
+
*/
|
|
56
|
+
private buildShimArgs;
|
|
57
|
+
/**
|
|
58
|
+
* Set up process event handlers.
|
|
59
|
+
*/
|
|
60
|
+
private setupProcessHandlers;
|
|
61
|
+
/**
|
|
62
|
+
* Kill the shim process gracefully.
|
|
63
|
+
* Sends SIGTERM and waits up to PROCESS_KILL_GRACE_MS for the process to exit.
|
|
64
|
+
* If the process doesn't exit in time, escalates to SIGKILL.
|
|
65
|
+
*/
|
|
66
|
+
kill(signal?: NodeJS.Signals): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Force-kill the shim process immediately with SIGKILL.
|
|
69
|
+
* Used by forceShutdown() when the user presses q/Ctrl+C a second time.
|
|
70
|
+
*/
|
|
71
|
+
forceKill(): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Clean up resources.
|
|
74
|
+
*/
|
|
75
|
+
private cleanup;
|
|
76
|
+
/**
|
|
77
|
+
* Check if process is running.
|
|
78
|
+
*/
|
|
79
|
+
isRunning(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Get process PID.
|
|
82
|
+
*/
|
|
83
|
+
getPid(): number | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Close log stream explicitly (for external cleanup).
|
|
86
|
+
*/
|
|
87
|
+
closeLogStream(): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Run the shim's self-test to verify environment setup.
|
|
90
|
+
* Executes the shim with --self-test flag and returns the results.
|
|
91
|
+
*
|
|
92
|
+
* @param command - Command to execute shim (e.g., ["bun", "shims/gemini/index.js"])
|
|
93
|
+
* @param providerId - Optional provider ID (e.g., "openai", "google") to set up provider-specific requirements
|
|
94
|
+
* @returns Promise resolving to self-test results
|
|
95
|
+
* @throws Error if self-test execution fails or returns invalid JSON
|
|
96
|
+
*/
|
|
97
|
+
runSelfTest(command: string[], providerId?: string): Promise<ShimSelfTestResult>;
|
|
98
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shim Runtime Extractor
|
|
3
|
+
*
|
|
4
|
+
* This module handles the extraction of bundled shim files at runtime for
|
|
5
|
+
* standalone executables. When compiled with Bun, shim files are embedded
|
|
6
|
+
* in the executable and need to be extracted to disk before they can be
|
|
7
|
+
* spawned as subprocesses.
|
|
8
|
+
*
|
|
9
|
+
* The extraction is done to a versioned directory to avoid re-extraction
|
|
10
|
+
* on every run and to handle version updates cleanly.
|
|
11
|
+
*
|
|
12
|
+
* Build Process:
|
|
13
|
+
* The build script (scripts/build-executable.ts) embeds shim files using:
|
|
14
|
+
* bun build --compile --embed shims/gemini/index.js ...
|
|
15
|
+
*
|
|
16
|
+
* Note: We use .js extension instead of .mjs for better embedding compatibility.
|
|
17
|
+
*
|
|
18
|
+
* At runtime, these embedded files are accessible via Bun.file() using their
|
|
19
|
+
* original paths.
|
|
20
|
+
*/
|
|
21
|
+
declare const SHIM_NAMES: readonly ["gemini", "codex", "pi", "opencode"];
|
|
22
|
+
type ShimName = (typeof SHIM_NAMES)[number];
|
|
23
|
+
/**
|
|
24
|
+
* Get the extraction directory path for shims.
|
|
25
|
+
* Uses ~/.hankweave/shims/<version>/ by default.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getShimExtractionDir(): string;
|
|
28
|
+
/**
|
|
29
|
+
* Get the path to an extracted shim file.
|
|
30
|
+
* Note: We use .js extension for embedding compatibility, even though the
|
|
31
|
+
* source file is .mjs. The file works the same regardless of extension.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getExtractedShimPath(shimName: ShimName): string;
|
|
34
|
+
/**
|
|
35
|
+
* Check if extraction is needed for a specific shim.
|
|
36
|
+
* Returns true if the file doesn't exist or is outdated.
|
|
37
|
+
*/
|
|
38
|
+
export declare function needsShimExtraction(shimName: ShimName): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Extract embedded shim files to the cache directory.
|
|
41
|
+
* This should be called when running from a compiled executable.
|
|
42
|
+
*
|
|
43
|
+
* Shims are embedded as .bundle (not .js) because Bun's --embed flag
|
|
44
|
+
* rebundles .js files instead of preserving raw bytes, which truncates
|
|
45
|
+
* large bundles like the Pi shim (10 MB → 28 KB). The .bundle extension
|
|
46
|
+
* bypasses this behaviour. We write them back out as .js on extraction.
|
|
47
|
+
*
|
|
48
|
+
* @returns Path to the extracted gemini shim (for backward compatibility)
|
|
49
|
+
*/
|
|
50
|
+
export declare function extractShimFiles(): Promise<string>;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# codex-shim
|
|
2
|
+
|
|
3
|
+
A self-contained Hankweave shim for OpenAI Codex built on `@openai/codex-sdk`.
|
|
4
|
+
|
|
5
|
+
The directory is packaged so it can be:
|
|
6
|
+
- dropped directly into Hankweave with `index.js` at the root
|
|
7
|
+
- rebuilt independently with `./rebuild.sh`
|
|
8
|
+
|
|
9
|
+
## Directory layout
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
shim/
|
|
13
|
+
├── index.js # drop-in bundle used by Hankweave
|
|
14
|
+
├── dist/index.js # build output
|
|
15
|
+
├── src/ # shim source
|
|
16
|
+
├── common/ # vendored @shims/common
|
|
17
|
+
├── docs/ # usage, architecture, and verification notes
|
|
18
|
+
├── rebuild.sh # reinstall + rebuild helper
|
|
19
|
+
├── VERSION # resolved primary SDK version
|
|
20
|
+
└── THIRDPARTY.md # third-party notices
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Requirements
|
|
24
|
+
|
|
25
|
+
- Node.js 18+
|
|
26
|
+
- Bun 1.1+
|
|
27
|
+
- Codex CLI available either on `PATH` or via `CODEX_PATH_OVERRIDE`
|
|
28
|
+
- Authentication configured via one of:
|
|
29
|
+
- `OPENAI_API_KEY`
|
|
30
|
+
- `CODEX_API_KEY`
|
|
31
|
+
- `~/.codex/auth.json`
|
|
32
|
+
|
|
33
|
+
## Quick start
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
cd shim
|
|
37
|
+
./rebuild.sh
|
|
38
|
+
|
|
39
|
+
echo "Say hello" | node ./index.js --model gpt-5.1-codex-max
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Common usage
|
|
43
|
+
|
|
44
|
+
Basic prompt:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
echo "Summarize this repository" | node ./index.js --model gpt-5.1-codex-max
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Resume a previous shim session:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
echo "Continue" | node ./index.js --model gpt-5.1-codex-max --resume <session_uuid>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Capture raw debug artifacts:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
echo "Inspect app startup" | node ./index.js \
|
|
60
|
+
--model gpt-5.1-codex-max \
|
|
61
|
+
--debug-dir ./debug-run
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Run the environment self-test:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
node ./index.js --self-test
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Supported flags
|
|
71
|
+
|
|
72
|
+
- `--model <model>`
|
|
73
|
+
- `--resume <session_id>`
|
|
74
|
+
- `--verbose`
|
|
75
|
+
- `--append-system-prompt <text>`
|
|
76
|
+
- `--idle-timeout <seconds>`
|
|
77
|
+
- `--debug-dir <path>`
|
|
78
|
+
- `--sandbox <none|standard|strict>`
|
|
79
|
+
- `--self-test`
|
|
80
|
+
- `--version`
|
|
81
|
+
- `--help`
|
|
82
|
+
|
|
83
|
+
## Model handling
|
|
84
|
+
|
|
85
|
+
The shim preserves the public model string in output while mapping it into Codex SDK options.
|
|
86
|
+
|
|
87
|
+
Examples:
|
|
88
|
+
- `gpt-5.1-codex-max` → used directly
|
|
89
|
+
- `openai/gpt-5.2-high` → public output stays prefixed, SDK model becomes `gpt-5.2`, reasoning effort becomes `high`
|
|
90
|
+
- `gpt-5.2-xhigh` → SDK model `gpt-5.2`, reasoning effort `xhigh`
|
|
91
|
+
|
|
92
|
+
## Tool normalization
|
|
93
|
+
|
|
94
|
+
Codex often reports file work as shell commands. The shim normalizes common patterns into structured shim tools:
|
|
95
|
+
|
|
96
|
+
- `cat file.txt` → `Read`
|
|
97
|
+
- `ls ...` → `LS`
|
|
98
|
+
- `rg ...` / `grep ...` → `Grep`
|
|
99
|
+
- `find ...` / `fd ...` → `Glob`
|
|
100
|
+
- `printf '...' > file.txt` → `Write`
|
|
101
|
+
- heredoc file writes → `Write`
|
|
102
|
+
- unknown shell commands → `Bash`
|
|
103
|
+
- Codex web tooling may surface as `WebSearch`, `WebFetch`, or passthrough MCP tool names
|
|
104
|
+
|
|
105
|
+
## Session storage
|
|
106
|
+
|
|
107
|
+
- With `--debug-dir`, shim session mappings are stored in `<debug-dir>/sessions/`
|
|
108
|
+
- Without `--debug-dir`, mappings are stored outside the project tree in `~/.shim/sessions/`
|
|
109
|
+
|
|
110
|
+
This preserves resume support without creating unexpected files in the workspace.
|
|
111
|
+
|
|
112
|
+
## More documentation
|
|
113
|
+
|
|
114
|
+
- `docs/usage.md`
|
|
115
|
+
- `docs/architecture.md`
|
|
116
|
+
- `docs/verification.md`
|
|
117
|
+
|
|
118
|
+
## Rebuild
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
./rebuild.sh
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`rebuild.sh`:
|
|
125
|
+
1. runs `bun install`
|
|
126
|
+
2. runs `bun run build`
|
|
127
|
+
3. updates `VERSION`
|
|
128
|
+
4. ensures `dist/index.js` has a Node shebang and executable bit
|
|
129
|
+
5. copies `dist/index.js` to root `index.js`
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Third-Party Notices
|
|
2
|
+
|
|
3
|
+
This shim bundles and/or depends on third-party code.
|
|
4
|
+
|
|
5
|
+
## Primary SDK dependency
|
|
6
|
+
|
|
7
|
+
### `@openai/codex-sdk` 0.112.0
|
|
8
|
+
- License: Apache-2.0
|
|
9
|
+
- Copyright holder: OpenAI
|
|
10
|
+
- Source: https://github.com/openai/codex/tree/main/sdk/typescript
|
|
11
|
+
- Package: https://www.npmjs.com/package/@openai/codex-sdk
|
|
12
|
+
|
|
13
|
+
The full license text can be found in the published npm package (for example under `node_modules/@openai/codex-sdk/LICENSE` after `bun install`) or in the upstream source repository.
|
|
14
|
+
|
|
15
|
+
## Vendored shared shim utilities
|
|
16
|
+
|
|
17
|
+
### `@shims/common`
|
|
18
|
+
`@shims/common` is vendored into `shim/common/` as first-party shared code from the shim workspace rather than as a third-party package.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.112.0
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shims/common",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Shared utilities for agent shims",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.ts",
|
|
9
|
+
"./args": "./src/args.ts",
|
|
10
|
+
"./messages": "./src/messages.ts",
|
|
11
|
+
"./tools": "./src/tools.ts",
|
|
12
|
+
"./sessions": "./src/sessions.ts",
|
|
13
|
+
"./timeout": "./src/timeout.ts"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "bun test",
|
|
17
|
+
"typecheck": "tsc --noEmit",
|
|
18
|
+
"clean": "echo 'No build artifacts to clean'"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/bun": "latest",
|
|
22
|
+
"typescript": "^5.3.0"
|
|
23
|
+
}
|
|
24
|
+
}
|