@crewhaus/runtime-core 0.1.1 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewhaus/runtime-core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "Minimal runtime imported by generated harness bundles",
6
6
  "main": "src/index.ts",
@@ -13,53 +13,54 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "@anthropic-ai/sdk": "^0.96.0",
16
- "@crewhaus/abort-controller": "0.1.1",
17
- "@crewhaus/adapter-anthropic": "0.1.1",
18
- "@crewhaus/agent-context-isolation": "0.1.1",
19
- "@crewhaus/boundary-classifier": "0.1.1",
20
- "@crewhaus/circuit-breaker": "0.1.1",
21
- "@crewhaus/compaction-autocompact": "0.1.1",
22
- "@crewhaus/compaction-snip": "0.1.1",
23
- "@crewhaus/cost-tracker": "0.1.1",
24
- "@crewhaus/egress-classifier": "0.1.1",
25
- "@crewhaus/errors": "0.1.1",
26
- "@crewhaus/event-log": "0.1.1",
27
- "@crewhaus/hooks-engine": "0.1.1",
28
- "@crewhaus/model-router": "0.1.1",
29
- "@crewhaus/permission-engine": "0.1.1",
30
- "@crewhaus/prompt-cache-manager": "0.1.1",
31
- "@crewhaus/prompt-injection-detector": "0.1.1",
32
- "@crewhaus/rate-limiter": "0.1.1",
33
- "@crewhaus/recovery-engine": "0.1.1",
34
- "@crewhaus/run-context": "0.1.1",
35
- "@crewhaus/session-store": "0.1.1",
36
- "@crewhaus/skills-registry": "0.1.1",
37
- "@crewhaus/slash-commands": "0.1.1",
38
- "@crewhaus/state-store": "0.1.1",
39
- "@crewhaus/token-budget": "0.1.1",
40
- "@crewhaus/tool-catalog": "0.1.1",
41
- "@crewhaus/tool-executor": "0.1.1",
42
- "@crewhaus/tool-loop-detection": "0.1.1",
43
- "@crewhaus/tool-orchestrator": "0.1.1",
44
- "@crewhaus/tool-result-store": "0.1.1",
45
- "@crewhaus/streaming-tool-executor": "0.1.1",
46
- "@crewhaus/turn-state-machine": "0.1.1",
47
- "@crewhaus/trace-event-bus": "0.1.1",
48
- "@crewhaus/structured-event-printer": "0.1.1",
49
- "@crewhaus/metrics-collector": "0.1.1",
50
- "@crewhaus/otel-exporter": "0.1.1",
16
+ "@crewhaus/abort-controller": "0.1.2",
17
+ "@crewhaus/adapter-anthropic": "0.1.2",
18
+ "@crewhaus/agent-context-isolation": "0.1.2",
19
+ "@crewhaus/boundary-classifier": "0.1.2",
20
+ "@crewhaus/circuit-breaker": "0.1.2",
21
+ "@crewhaus/compaction-autocompact": "0.1.2",
22
+ "@crewhaus/compaction-snip": "0.1.2",
23
+ "@crewhaus/cost-tracker": "0.1.2",
24
+ "@crewhaus/egress-classifier": "0.1.2",
25
+ "@crewhaus/errors": "0.1.2",
26
+ "@crewhaus/event-log": "0.1.2",
27
+ "@crewhaus/hooks-engine": "0.1.2",
28
+ "@crewhaus/model-router": "0.1.2",
29
+ "@crewhaus/permission-engine": "0.1.2",
30
+ "@crewhaus/prompt-cache-manager": "0.1.2",
31
+ "@crewhaus/prompt-injection-detector": "0.1.2",
32
+ "@crewhaus/rate-limiter": "0.1.2",
33
+ "@crewhaus/recovery-engine": "0.1.2",
34
+ "@crewhaus/run-context": "0.1.2",
35
+ "@crewhaus/session-store": "0.1.2",
36
+ "@crewhaus/skills-registry": "0.1.2",
37
+ "@crewhaus/slash-commands": "0.1.2",
38
+ "@crewhaus/state-store": "0.1.2",
39
+ "@crewhaus/tenancy": "0.1.2",
40
+ "@crewhaus/token-budget": "0.1.2",
41
+ "@crewhaus/tool-catalog": "0.1.2",
42
+ "@crewhaus/tool-executor": "0.1.2",
43
+ "@crewhaus/tool-loop-detection": "0.1.2",
44
+ "@crewhaus/tool-orchestrator": "0.1.2",
45
+ "@crewhaus/tool-result-store": "0.1.2",
46
+ "@crewhaus/streaming-tool-executor": "0.1.2",
47
+ "@crewhaus/turn-state-machine": "0.1.2",
48
+ "@crewhaus/trace-event-bus": "0.1.2",
49
+ "@crewhaus/structured-event-printer": "0.1.2",
50
+ "@crewhaus/metrics-collector": "0.1.2",
51
+ "@crewhaus/otel-exporter": "0.1.2",
51
52
  "zod-to-json-schema": "^3.23.5"
52
53
  },
53
54
  "devDependencies": {
54
- "@crewhaus/logging": "0.1.1",
55
- "@crewhaus/tool-builder": "0.1.1",
55
+ "@crewhaus/logging": "0.1.2",
56
+ "@crewhaus/tool-builder": "0.1.2",
56
57
  "zod": "^3.23.8"
57
58
  },
58
59
  "license": "Apache-2.0",
59
60
  "author": {
60
61
  "name": "Max Meier",
61
- "email": "max@studiomax.io",
62
- "url": "https://studiomax.io"
62
+ "email": "max@crewhaus.ai",
63
+ "url": "https://crewhaus.ai"
63
64
  },
64
65
  "repository": {
65
66
  "type": "git",
@@ -71,12 +72,7 @@
71
72
  "url": "https://github.com/crewhaus/factory/issues"
72
73
  },
73
74
  "publishConfig": {
74
- "access": "restricted"
75
+ "access": "public"
75
76
  },
76
- "files": [
77
- "src",
78
- "README.md",
79
- "LICENSE",
80
- "NOTICE"
81
- ]
77
+ "files": ["src", "README.md", "LICENSE", "NOTICE"]
82
78
  }
@@ -4,7 +4,7 @@
4
4
  * inline bold/italic/code, blockquotes, and graceful handling of
5
5
  * tokens split across chunks.
6
6
  */
7
- import { describe, expect, test } from "bun:test";
7
+ import { describe, expect, spyOn, test } from "bun:test";
8
8
  import { createCliMarkdownRenderer, isCliMarkdownEnabled } from "./cli-markdown";
9
9
 
10
10
  function capture(): { write: (s: string) => void; out: () => string } {
@@ -135,6 +135,18 @@ describe("createCliMarkdownRenderer", () => {
135
135
  expect(strip(c.out())).toMatch(/^─{40}/);
136
136
  });
137
137
 
138
+ test("underscore bold (__x__) and underscore italic (_x_) render", () => {
139
+ const c = capture();
140
+ const r = createCliMarkdownRenderer({ write: c.write });
141
+ // __bold__ exercises the __...__ replace callback; a closed _italic_ pair
142
+ // (word-boundary guarded) exercises the _..._ replace callback. Both are
143
+ // distinct from the asterisk variants the other tests cover.
144
+ r.push("make __this__ and _that_ pop\n");
145
+ expect(strip(c.out())).toBe("make this and that pop\n");
146
+ expect(c.out()).toContain("\x1b[1m"); // bold from __this__
147
+ expect(c.out()).toContain("\x1b[3m"); // italic from _that_
148
+ });
149
+
138
150
  test("does not false-match snake_case identifiers as italic", () => {
139
151
  const c = capture();
140
152
  const r = createCliMarkdownRenderer({ write: c.write });
@@ -153,6 +165,28 @@ describe("createCliMarkdownRenderer", () => {
153
165
  expect(stripped).toContain("code");
154
166
  expect(stripped).toContain("• item two");
155
167
  });
168
+
169
+ test("defaults to process.stdout.write when no write override is supplied", () => {
170
+ // Exercises the default sink arrow `(s) => process.stdout.write(s)` that
171
+ // every other test bypasses by passing an explicit `write`. We spy on
172
+ // stdout so nothing actually prints to the test console.
173
+ const written: string[] = [];
174
+ const spy = spyOn(process.stdout, "write").mockImplementation(((chunk: unknown) => {
175
+ written.push(String(chunk));
176
+ return true;
177
+ }) as typeof process.stdout.write);
178
+ try {
179
+ const r = createCliMarkdownRenderer(); // no opts → default write
180
+ r.push("plain line\n"); // flushes a completed line via the default sink
181
+ r.push("tail-no-newline");
182
+ r.end(); // flushes the buffered tail via the default sink
183
+ } finally {
184
+ spy.mockRestore();
185
+ }
186
+ const joined = strip(written.join(""));
187
+ expect(joined).toContain("plain line");
188
+ expect(joined).toContain("tail-no-newline");
189
+ });
156
190
  });
157
191
 
158
192
  describe("isCliMarkdownEnabled", () => {
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Regression — Section 27 cost tracking over the live `runChatLoop` path
3
+ * with provider-prefixed spec model strings.
4
+ *
5
+ * `model_response` used to publish the raw spec string
6
+ * (`"bedrock/us.anthropic.claude-…"`, `"openai/gpt-4o"`); cost-tracker
7
+ * pricing keys are bare wire model ids, so every prefixed run was a
8
+ * silent pricing miss charged $0 — only unprefixed `claude-*` strings
9
+ * priced. These tests run the real loop (stub adapter) against a
10
+ * cost-tracker on the run bus and assert non-zero cost, zero misses, and
11
+ * the wire-id/spec-string split on the published events.
12
+ */
13
+ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
14
+ import { mkdtempSync, rmSync } from "node:fs";
15
+ import { tmpdir } from "node:os";
16
+ import { join } from "node:path";
17
+ import type { ProviderAdapter } from "@crewhaus/adapter-anthropic";
18
+ import { createCostTracker } from "@crewhaus/cost-tracker";
19
+ import { createRunContext } from "@crewhaus/run-context";
20
+ import type {
21
+ CostAccrualEvent,
22
+ ModelResponseEvent,
23
+ ProviderId,
24
+ TraceEvent,
25
+ } from "@crewhaus/trace-event-bus";
26
+ import { runChatLoop } from "./index";
27
+
28
+ const SHARED_SESSION_ROOT = mkdtempSync(join(tmpdir(), "crewhaus-cost-wire-model-tests-"));
29
+ beforeAll(() => {
30
+ process.env["CREWHAUS_SESSION_DIR"] = SHARED_SESSION_ROOT;
31
+ });
32
+ afterAll(() => {
33
+ process.env["CREWHAUS_SESSION_DIR"] = undefined;
34
+ rmSync(SHARED_SESSION_ROOT, { recursive: true, force: true });
35
+ });
36
+
37
+ /** Single text-only turn: 100 input tokens, 10 output tokens. */
38
+ function makeTextAdapter(providerId: ProviderId): ProviderAdapter {
39
+ return {
40
+ providerId,
41
+ features: {
42
+ caching: "explicit",
43
+ tool_use: true,
44
+ vision: true,
45
+ thinking: false,
46
+ web_search: false,
47
+ },
48
+ estimateTokens: () => 0,
49
+ stream: () =>
50
+ (async function* () {
51
+ yield { kind: "message_start", usage: { input: 100, output: 0 } } as const;
52
+ yield {
53
+ kind: "content_block_start",
54
+ index: 0,
55
+ block: { type: "text", text: "" },
56
+ } as const;
57
+ yield {
58
+ kind: "content_block_delta",
59
+ index: 0,
60
+ delta: { type: "text_delta", text: "ok" },
61
+ } as const;
62
+ yield { kind: "content_block_stop", index: 0 } as const;
63
+ yield {
64
+ kind: "message_delta",
65
+ stopReason: "end_turn",
66
+ usage: { input: 100, output: 10 },
67
+ } as const;
68
+ yield { kind: "message_stop" } as const;
69
+ })(),
70
+ };
71
+ }
72
+
73
+ async function runOnce(model: string, providerId: ProviderId) {
74
+ const runContext = createRunContext();
75
+ const seen: TraceEvent[] = [];
76
+ runContext.eventBus.subscribe((e) => {
77
+ seen.push(e);
78
+ });
79
+ const tracker = createCostTracker(runContext.eventBus);
80
+ await runChatLoop({
81
+ model,
82
+ instructions: "test",
83
+ _adapter: makeTextAdapter(providerId),
84
+ runContext,
85
+ singleTurn: true,
86
+ seedMessages: [{ role: "user", content: "hello" }],
87
+ });
88
+ tracker.unsubscribe();
89
+ const responses = seen.filter((e): e is ModelResponseEvent => e.kind === "model_response");
90
+ const accruals = seen.filter((e): e is CostAccrualEvent => e.kind === "cost_accrual");
91
+ return { tracker, responses, accruals, runId: runContext.eventBus.runId };
92
+ }
93
+
94
+ describe("cost tracking with provider-prefixed spec model strings", () => {
95
+ test("bedrock inference-profile spec string prices — no $0 pricing miss", async () => {
96
+ const spec = "bedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0";
97
+ const wire = "us.anthropic.claude-sonnet-4-5-20250929-v1:0";
98
+ const { tracker, responses, accruals, runId } = await runOnce(spec, "bedrock");
99
+
100
+ expect(responses.length).toBe(1);
101
+ expect(responses[0]?.model).toBe(wire);
102
+ expect(responses[0]?.specModel).toBe(spec);
103
+
104
+ expect(tracker.pricingMisses()).toBe(0);
105
+ expect(tracker.observed()).toBe(1);
106
+ // anthropic.claude-sonnet-4 row: 100 in × $3/M + 10 out × $15/M = 450 micros
107
+ expect(tracker.getRunCost(runId).totalUsdMicros).toBe(450);
108
+ expect(tracker.getRunCost(runId).byProvider.bedrock).toBe(450);
109
+
110
+ expect(accruals.length).toBe(1);
111
+ expect(accruals[0]?.modelId).toBe(wire);
112
+ expect(accruals[0]?.specModel).toBe(spec);
113
+ expect(accruals[0]?.costUsdMicros).toBe(450);
114
+ });
115
+
116
+ test("openai/* spec string prices — no $0 pricing miss", async () => {
117
+ const { tracker, responses, accruals, runId } = await runOnce("openai/gpt-4o", "openai");
118
+
119
+ expect(responses[0]?.model).toBe("gpt-4o");
120
+ expect(responses[0]?.specModel).toBe("openai/gpt-4o");
121
+
122
+ expect(tracker.pricingMisses()).toBe(0);
123
+ // gpt-4o row: 100 in × $2.5/M + 10 out × $10/M = 350 micros
124
+ expect(tracker.getRunCost(runId).byProvider.openai).toBe(350);
125
+ expect(accruals[0]?.modelId).toBe("gpt-4o");
126
+ });
127
+
128
+ test("unprefixed claude-* spec string still prices; no specModel published", async () => {
129
+ const { tracker, responses, accruals, runId } = await runOnce("claude-sonnet-4-6", "anthropic");
130
+
131
+ expect(responses[0]?.model).toBe("claude-sonnet-4-6");
132
+ expect(responses[0]?.specModel).toBeUndefined();
133
+
134
+ expect(tracker.pricingMisses()).toBe(0);
135
+ expect(tracker.getRunCost(runId).byProvider.anthropic).toBe(450);
136
+ expect(accruals[0]?.specModel).toBeUndefined();
137
+ });
138
+ });