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.
Files changed (79) hide show
  1. package/README.md +12 -11
  2. package/dist/base-process-manager.d.ts +30 -0
  3. package/dist/budget.d.ts +315 -0
  4. package/dist/checkpoint-git.d.ts +98 -0
  5. package/dist/claude-agent-sdk-manager.d.ts +144 -0
  6. package/dist/claude-log-parser.d.ts +63 -0
  7. package/dist/claude-runtime-extractor.d.ts +73 -0
  8. package/dist/codex-runtime-extractor.d.ts +107 -0
  9. package/dist/codon-runner.d.ts +278 -0
  10. package/dist/config-validation/model-validator.d.ts +16 -0
  11. package/dist/config-validation/sentinel.schema.d.ts +6967 -0
  12. package/dist/config.d.ts +40815 -0
  13. package/dist/cost-tracker.d.ts +72 -0
  14. package/dist/execution-planner.d.ts +62 -0
  15. package/dist/execution-thread.d.ts +71 -0
  16. package/dist/exports/schemas.d.ts +9 -0
  17. package/dist/exports/schemas.js +1019 -0
  18. package/dist/exports/types.d.ts +15 -0
  19. package/dist/exports/types.js +60 -0
  20. package/dist/file-resolver.d.ts +33 -0
  21. package/dist/index.js +380 -293
  22. package/dist/index.js.map +33 -29
  23. package/dist/llm/llm-provider-registry.d.ts +207 -0
  24. package/dist/llm/models-dev-schema.d.ts +679 -0
  25. package/dist/llm/provider-config.d.ts +30 -0
  26. package/dist/prompt-builder.d.ts +75 -0
  27. package/dist/prompt-frontmatter.d.ts +61 -0
  28. package/dist/replay-process-manager.d.ts +82 -0
  29. package/dist/runtime-extractor-base.d.ts +120 -0
  30. package/dist/schemas/event-schemas.d.ts +8389 -0
  31. package/dist/schemas/websocket-log-schemas.d.ts +4502 -0
  32. package/dist/shim-process-manager.d.ts +98 -0
  33. package/dist/shim-runtime-extractor.d.ts +51 -0
  34. package/dist/shims/codex/README.md +129 -0
  35. package/dist/shims/codex/THIRDPARTY.md +18 -0
  36. package/dist/shims/codex/VERSION +1 -0
  37. package/dist/shims/codex/common/package.json +24 -0
  38. package/dist/shims/codex/index.js +1154 -970
  39. package/dist/shims/codex/package.json +46 -0
  40. package/dist/shims/codex/tsup.config.ts +16 -0
  41. package/dist/shims/gemini/README.md +59 -0
  42. package/dist/shims/gemini/THIRDPARTY.md +32 -0
  43. package/dist/shims/gemini/VERSION +1 -0
  44. package/dist/shims/gemini/common/package.json +24 -0
  45. package/dist/shims/gemini/index.js +1359 -30
  46. package/dist/shims/gemini/package.json +37 -0
  47. package/dist/shims/opencode/README.md +82 -0
  48. package/dist/shims/opencode/THIRDPARTY.md +32 -0
  49. package/dist/shims/opencode/VERSION +1 -0
  50. package/dist/shims/opencode/common/package.json +24 -0
  51. package/dist/shims/opencode/index.js +1476 -0
  52. package/dist/shims/opencode/package.json +38 -0
  53. package/dist/shims/pi/README.md +87 -0
  54. package/dist/shims/pi/THIRDPARTY.md +24 -0
  55. package/dist/shims/pi/VERSION +1 -0
  56. package/dist/shims/pi/common/package.json +24 -0
  57. package/dist/shims/pi/index.js +249832 -0
  58. package/dist/shims/pi/package.json +53 -0
  59. package/dist/state-manager.d.ts +161 -0
  60. package/dist/state-transition-guards.d.ts +37 -0
  61. package/dist/telemetry/telemetry-types.d.ts +206 -0
  62. package/dist/typed-event-emitter.d.ts +57 -0
  63. package/dist/types/branded-types.d.ts +15 -0
  64. package/dist/types/budget-types.d.ts +82 -0
  65. package/dist/types/claude-session-schema.d.ts +2430 -0
  66. package/dist/types/error-types.d.ts +44 -0
  67. package/dist/types/input-ai-types.d.ts +1070 -0
  68. package/dist/types/llm-call-types.d.ts +3829 -0
  69. package/dist/types/sentinel-types.d.ts +66 -0
  70. package/dist/types/state-types.d.ts +1099 -0
  71. package/dist/types/tool-types.d.ts +86 -0
  72. package/dist/types/types.d.ts +367 -0
  73. package/dist/types/websocket-log-types.d.ts +7 -0
  74. package/dist/utils.d.ts +452 -0
  75. package/package.json +15 -2
  76. package/schemas/hank.schema.json +158 -3
  77. package/schemas/hankweave.schema.json +17 -1
  78. package/shims/codex/index.js +0 -1583
  79. package/shims/gemini/index.js +0 -31
@@ -0,0 +1,72 @@
1
+ import type { LlmProviderRegistry } from "./llm/llm-provider-registry.js";
2
+ import { TypedEventEmitter } from "./typed-event-emitter.js";
3
+ import type { TokenUsage } from "./types/types.js";
4
+ import type { Logger } from "./utils.js";
5
+ /**
6
+ * Raw API usage fields from assistant messages.
7
+ */
8
+ export interface RawApiUsage {
9
+ input_tokens?: number;
10
+ output_tokens?: number;
11
+ cache_creation_input_tokens?: number;
12
+ cache_read_input_tokens?: number;
13
+ }
14
+ /**
15
+ * Raw fields from a result message relevant to cost tracking.
16
+ */
17
+ export interface RawResultUsage {
18
+ usage?: RawApiUsage;
19
+ total_cost_usd?: number;
20
+ modelUsage?: unknown;
21
+ }
22
+ /**
23
+ * Events emitted by CostTracker.
24
+ */
25
+ export interface CostTrackerEvents extends Record<string, unknown[]> {
26
+ /** Incremental cost from an assistant message */
27
+ costIncremented: [delta: {
28
+ cost: number;
29
+ tokens: TokenUsage;
30
+ }];
31
+ /** Authoritative final cost from result message */
32
+ finalCostSet: [
33
+ final: {
34
+ cost: number;
35
+ tokens: TokenUsage;
36
+ modelUsage?: unknown;
37
+ modelId?: string;
38
+ }
39
+ ];
40
+ }
41
+ /**
42
+ * Encapsulates cost computation and accumulation for a single codon execution.
43
+ *
44
+ * Receives raw API messages, calculates costs via LlmProviderRegistry, maintains
45
+ * running totals, and emits typed events for external consumers (state transitions,
46
+ * event broadcasting).
47
+ *
48
+ * Owned by CodonRunner. The runtime subscribes to its events.
49
+ */
50
+ export declare class CostTracker extends TypedEventEmitter<CostTrackerEvents> {
51
+ private readonly modelId;
52
+ private readonly llmRegistry;
53
+ private readonly logger;
54
+ private runningCost;
55
+ private runningTokens;
56
+ constructor(modelId: string | undefined, llmRegistry: LlmProviderRegistry, logger: Logger);
57
+ /**
58
+ * Process usage from an assistant message. Calculates incremental cost,
59
+ * accumulates running totals, and emits costIncremented.
60
+ */
61
+ handleAssistantUsage(usage: RawApiUsage): void;
62
+ /**
63
+ * Process usage from a result message. Resolves authoritative final cost
64
+ * using priority chain (CLI-provided > registry calc > accumulated fallback),
65
+ * logs discrepancies, and emits finalCostSet.
66
+ */
67
+ handleResultUsage(msg: RawResultUsage): void;
68
+ /** Current accumulated cost (for logging/fallback). */
69
+ getRunningCost(): number;
70
+ /** Current accumulated token usage. */
71
+ getRunningTokens(): TokenUsage;
72
+ }
@@ -0,0 +1,62 @@
1
+ import { CodonId } from "./types/branded-types.js";
2
+ import type { AllocationMode } from "./types/budget-types.js";
3
+ import type { Codon, CodonConfig } from "./types/types.js";
4
+ /**
5
+ * Represents a flattened codon in the execution plan.
6
+ * Each entry is a concrete codon that will be executed.
7
+ */
8
+ export interface ExecutionCodonEntry {
9
+ codon: Codon;
10
+ codonId: CodonId;
11
+ loopContext?: {
12
+ loopId: CodonId;
13
+ iteration: number;
14
+ codonIndexInLoop: number;
15
+ loopBudget?: {
16
+ maxDollars?: number;
17
+ maxTimeSeconds?: number;
18
+ allocation?: AllocationMode;
19
+ shares?: Record<string, number>;
20
+ onExceeded?: "complete" | "fail";
21
+ };
22
+ };
23
+ }
24
+ /**
25
+ * Handles all execution planning logic.
26
+ * Pure functions - no side effects, just config → plan transformations.
27
+ */
28
+ export declare class ExecutionPlanner {
29
+ private codonConfigs;
30
+ constructor(codonConfigs: CodonConfig[]);
31
+ /**
32
+ * Build initial execution plan for fresh start.
33
+ * Expands only the first iteration of each loop.
34
+ */
35
+ buildInitialPlan(): ExecutionCodonEntry[];
36
+ /**
37
+ * Expand next iteration after codon completion.
38
+ * Returns new plan with next iteration injected (if termination not met).
39
+ * Pure function - doesn't mutate input plan.
40
+ */
41
+ expandNextIteration(params: {
42
+ currentPlan: ExecutionCodonEntry[];
43
+ completedCodonId: CodonId;
44
+ contextExceeded?: boolean;
45
+ budgetExceeded?: boolean;
46
+ }): ExecutionCodonEntry[];
47
+ /**
48
+ * Validate the execution plan for consistency.
49
+ * Catches configuration errors before execution.
50
+ */
51
+ validatePlan(plan: ExecutionCodonEntry[]): void;
52
+ /**
53
+ * Create execution plan for a specific iteration of a loop.
54
+ */
55
+ private createIterationPlan;
56
+ /**
57
+ * Generate a unique codon ID for a loop iteration.
58
+ * Format: "originalId#iteration" where iteration is 0-indexed
59
+ * Examples: "review#0", "review#1", "review#2"
60
+ */
61
+ private generateIterationCodonId;
62
+ }
@@ -0,0 +1,71 @@
1
+ import { type CodonExecution, type CodonId, type HankweaveState, type RunId, type SessionId } from "./types/state-types.js";
2
+ import type { Logger } from "./utils.js";
3
+ /**
4
+ * Complete checkpoint information including git metadata
5
+ */
6
+ export interface CheckpointInfo {
7
+ type: "rig-setup" | "completed" | "error" | "skipped";
8
+ sha: string;
9
+ message: string;
10
+ timestamp: string;
11
+ branch: string;
12
+ }
13
+ /**
14
+ * A codon with its complete context
15
+ */
16
+ export interface ThreadCodon {
17
+ codon: CodonExecution;
18
+ runId: RunId;
19
+ runStatus: "running" | "completed" | "failed" | "crashed";
20
+ runStartTime: string;
21
+ runEndTime: string | null;
22
+ gitBranch: string;
23
+ globalIndex: number;
24
+ runIndex: number;
25
+ codonIndexInRun: number;
26
+ validatedCheckpoints: CheckpointInfo[];
27
+ continuationSessionId: SessionId | null;
28
+ }
29
+ /**
30
+ * Complete execution thread
31
+ */
32
+ export declare class ExecutionThread {
33
+ codons: ThreadCodon[];
34
+ totalRuns: number;
35
+ hasRunningCodon: boolean;
36
+ nextCodonId: CodonId | null;
37
+ constructor(codons?: ThreadCodon[], totalRuns?: number, hasRunningCodon?: boolean, nextCodonId?: CodonId | null);
38
+ /**
39
+ * Check if the execution thread is in a failed state.
40
+ *
41
+ * The thread is considered failed only if:
42
+ * 1. The most recent codon explicitly has status "failed"
43
+ * 2. OR the run crashed/failed while a codon was still running (non-terminal state)
44
+ *
45
+ * Historical runs being marked as "failed" (e.g., due to server shutdown after
46
+ * successful codon completion) should NOT cause the thread to be considered failed.
47
+ */
48
+ get failed(): boolean;
49
+ }
50
+ /**
51
+ * Analyze execution history to build a unified thread with all metadata.
52
+ *
53
+ * @param state - The complete Hankweave state (including executionPlan)
54
+ * @param checkpointData - Map of SHA to git checkpoint data (optional)
55
+ * @param targetRunId - Specific run to analyze (defaults to latest)
56
+ * @param logger - Optional logger for debugging
57
+ * @returns Complete execution thread with all metadata preserved
58
+ */
59
+ export declare function analyzeExecutionThread(state: HankweaveState, checkpointData?: Map<string, {
60
+ message: string;
61
+ timestamp: string;
62
+ branch: string;
63
+ }>, targetRunId?: RunId, logger?: Logger): Promise<ExecutionThread>;
64
+ /**
65
+ * Get the next codon to execute from a thread
66
+ */
67
+ export declare function getNextCodonId(thread: ExecutionThread): CodonId | null;
68
+ /**
69
+ * Find session ID for continuing a specific codon
70
+ */
71
+ export declare function findContinuationSessionId(thread: ExecutionThread, codonId: CodonId, state: HankweaveState): SessionId | null;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Public schema exports for external consumers (e.g., hw-tracing).
3
+ *
4
+ * Exports Zod schemas and inferred TypeScript types for:
5
+ * - Server events (events.jsonl)
6
+ * - Per-codon log messages (claude session JSONL)
7
+ */
8
+ export { type AssistantActionEvent, assistantActionEventDataSchema, assistantActionEventSchema, type BudgetSummaryEvent, budgetSummaryEventSchema, type CodonCompletedEvent, type CodonExtendedEvent, type CodonStartedEvent, codonCompletedEventDataSchema, codonCompletedEventSchema, codonExtendedEventSchema, codonStartedEventDataSchema, codonStartedEventSchema, type ErrorEvent, errorEventSchema, type FileUpdatedEvent, fileUpdatedEventSchema, type InfoEvent, infoEventSchema, isAgenticBackboneEvent, isConnectionStateEvent, isSentinelEvent, isServerStateEvent, type LoopIterationCompletedEvent, loopIterationCompletedEventDataSchema, loopIterationCompletedEventSchema, type RigOutputEvent, type RigSetupCompletedEvent, type RigSetupFailedEvent, rigOutputEventSchema, rigSetupCompletedEventDataSchema, rigSetupCompletedEventSchema, rigSetupFailedEventDataSchema, rigSetupFailedEventSchema, type SentinelErrorEvent, type SentinelLoadedEvent, type SentinelOutputEvent, type SentinelTriggeredEvent, type SentinelUnloadedEvent, type ServerEvent, type ServerReadyEvent, sentinelErrorEventSchema, sentinelLoadedEventDataSchema, sentinelLoadedEventSchema, sentinelOutputEventDataSchema, sentinelOutputEventSchema, sentinelTriggeredEventSchema, sentinelUnloadedEventDataSchema, sentinelUnloadedEventSchema, serverEventSchema, serverReadyEventSchema, type TokenUsageEvent, type ToolResultEvent, tokenUsageEventDataSchema, tokenUsageEventSchema, toolResultEventDataSchema, toolResultEventSchema, } from "../schemas/event-schemas.js";
9
+ export { type AssistantMessage, assistantMessageSchema, type LogMessage, logMessageSchema, messageContentSchema, type ResultMessage, resultMessageSchema, type SystemMessage, systemMessageSchema, type TextContent, type ThinkingContent, type ToolResultContent, type ToolUseContent, textContentSchema, thinkingContentSchema, toolResultContentSchema, toolUseContentSchema, type UserMessage, userMessageSchema, } from "../types/claude-session-schema.js";