@crewhaus/runtime-core 0.6.0 → 0.8.0
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 +201 -0
- package/NOTICE +9 -0
- package/README.md +9 -0
- package/dist/alert-watchdog.d.ts +17 -1
- package/dist/alert-watchdog.js +91 -18
- package/dist/cli-markdown-lines.d.ts +20 -0
- package/dist/cli-markdown-lines.js +91 -0
- package/dist/cli-markdown.js +15 -13
- package/dist/flatten-union.d.ts +36 -0
- package/dist/flatten-union.js +65 -0
- package/dist/forged-footer.d.ts +51 -0
- package/dist/forged-footer.js +212 -0
- package/dist/identity.js +47 -21
- package/dist/incident-collector.js +25 -6
- package/dist/index.d.ts +257 -19
- package/dist/index.js +2097 -200
- package/dist/lineage-screen.d.ts +33 -0
- package/dist/lineage-screen.js +46 -0
- package/dist/observability.d.ts +11 -3
- package/dist/observability.js +52 -13
- package/dist/path-canonical.d.ts +74 -0
- package/dist/path-canonical.js +676 -0
- package/dist/pre-route.d.ts +5 -3
- package/dist/state-roots.d.ts +12 -0
- package/dist/state-roots.js +79 -0
- package/dist/tool-limit.d.ts +54 -0
- package/dist/tool-limit.js +66 -0
- package/package.json +51 -44
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Tenant } from "@crewhaus/tenancy";
|
|
2
|
+
/**
|
|
3
|
+
* The runtime-state roots of a run: its session-log root (`sessionRootDir`
|
|
4
|
+
* as `runChatLoop` resolved it — the tenant's, `CREWHAUS_SESSION_DIR`, or
|
|
5
|
+
* event-log's default), its tool-result spill root (the tenant's
|
|
6
|
+
* `toolResultRoot`, else `<cwd>/.crewhaus/tool-results`, where the runtime
|
|
7
|
+
* saves an output too long for the log — `@crewhaus/tool-result-store`) and
|
|
8
|
+
* its proofs root (the tenant's `proofs/`, else `<cwd>/.crewhaus/proofs`,
|
|
9
|
+
* where every spec's bundles and artifacts live). The floor is on writes
|
|
10
|
+
* only: the model still reads a spilled output's parts.
|
|
11
|
+
*/
|
|
12
|
+
export declare function runtimeStateRoots(sessionRootDir: string | undefined, tenant: Tenant | undefined, cwd?: string): string[];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 0.8.0 (design/0.8.0-provability-release.md §1 principle 1, §5.2, §5.3) —
|
|
3
|
+
* where the runtime keeps its own record of a run: the session event logs
|
|
4
|
+
* (every `tool_use` input and `tool_result` output, verbatim — the evidence
|
|
5
|
+
* the provability gate grounds a claim on and `continuity.proof` resolves),
|
|
6
|
+
* the tool results the runtime spilled to a file (the whole output a long
|
|
7
|
+
* fetch grounds on, whose head alone the log holds) and the proof bundles
|
|
8
|
+
* (the audit artifact). Evidence is checked, never
|
|
9
|
+
* believed, only while the agent cannot write it: a `Write` that appends a
|
|
10
|
+
* hand-made fetch to the log would ground any text under any URL. The run
|
|
11
|
+
* hands these roots to permission-engine's runtime-state floor
|
|
12
|
+
* (`EvaluateOptions.protectedRoots`), which no rule can lift.
|
|
13
|
+
*
|
|
14
|
+
* Each root is given every way a path the canonicaliser produces can spell
|
|
15
|
+
* it: absolute as resolved, absolute with symlinks followed (macOS's
|
|
16
|
+
* `/var` → `/private/var`; a root that does not exist yet is followed as far
|
|
17
|
+
* as it does), and workspace-relative when it lies inside the working
|
|
18
|
+
* directory (what a tool that declares no operative arguments carries).
|
|
19
|
+
*/
|
|
20
|
+
import { realpathSync } from "node:fs";
|
|
21
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
22
|
+
import { DEFAULT_ROOT_DIR } from "@crewhaus/event-log";
|
|
23
|
+
import { DEFAULT_ROOT_DIR as TOOL_RESULTS_ROOT_DIR } from "@crewhaus/tool-result-store";
|
|
24
|
+
/** `path` with every symlink on its existing part followed, or `undefined` when nothing of it exists. */
|
|
25
|
+
function followed(path) {
|
|
26
|
+
const rest = [];
|
|
27
|
+
let head = path;
|
|
28
|
+
for (let depth = 0; depth < 256; depth += 1) {
|
|
29
|
+
try {
|
|
30
|
+
const real = realpathSync(head);
|
|
31
|
+
// Rebuilt one name at a time: the list is never spread into join.
|
|
32
|
+
return rest.reduceRight((built, name) => join(built, name), real);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
const parent = dirname(head);
|
|
36
|
+
if (parent === head)
|
|
37
|
+
return undefined;
|
|
38
|
+
rest.push(basename(head));
|
|
39
|
+
head = parent;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The runtime-state roots of a run: its session-log root (`sessionRootDir`
|
|
46
|
+
* as `runChatLoop` resolved it — the tenant's, `CREWHAUS_SESSION_DIR`, or
|
|
47
|
+
* event-log's default), its tool-result spill root (the tenant's
|
|
48
|
+
* `toolResultRoot`, else `<cwd>/.crewhaus/tool-results`, where the runtime
|
|
49
|
+
* saves an output too long for the log — `@crewhaus/tool-result-store`) and
|
|
50
|
+
* its proofs root (the tenant's `proofs/`, else `<cwd>/.crewhaus/proofs`,
|
|
51
|
+
* where every spec's bundles and artifacts live). The floor is on writes
|
|
52
|
+
* only: the model still reads a spilled output's parts.
|
|
53
|
+
*/
|
|
54
|
+
export function runtimeStateRoots(sessionRootDir, tenant, cwd = process.cwd()) {
|
|
55
|
+
const sessions = resolve(cwd, sessionRootDir ?? DEFAULT_ROOT_DIR);
|
|
56
|
+
const toolResults = resolve(cwd, tenant?.toolResultRoot ?? TOOL_RESULTS_ROOT_DIR);
|
|
57
|
+
const proofs = tenant !== undefined
|
|
58
|
+
? resolve(cwd, tenant.sessionRoot, "..", "proofs")
|
|
59
|
+
: resolve(cwd, ".crewhaus", "proofs");
|
|
60
|
+
const roots = new Set();
|
|
61
|
+
for (const root of [sessions, toolResults, proofs]) {
|
|
62
|
+
// A root that holds the working directory itself (a session dir pointed
|
|
63
|
+
// at the workspace) would refuse every write the agent makes: it is
|
|
64
|
+
// left to the permission rules rather than walled off whole.
|
|
65
|
+
const back = relative(root, cwd);
|
|
66
|
+
if (back === "" || (back !== ".." && !back.startsWith(`..${sep}`) && !isAbsolute(back))) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
roots.add(root);
|
|
70
|
+
const real = followed(root);
|
|
71
|
+
if (real !== undefined)
|
|
72
|
+
roots.add(real);
|
|
73
|
+
const rel = relative(cwd, root);
|
|
74
|
+
if (rel !== "" && rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)) {
|
|
75
|
+
roots.add(rel);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return [...roots];
|
|
79
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* provider-limits#0 — the boot check of the run's tool list against the
|
|
3
|
+
* per-request limit of each model that can be sent it.
|
|
4
|
+
*
|
|
5
|
+
* The compiler checks the spec's builtin tools; this is the authoritative
|
|
6
|
+
* check, because only the running loop knows the full list: the builtins plus
|
|
7
|
+
* the loop's own tools (ListTools, continuity, memory, Task, Skill), MCP
|
|
8
|
+
* server tools, plugin tools and the hybrid pair — and a `crewhaus run
|
|
9
|
+
* --model` override the compiler never saw. It runs before the first model
|
|
10
|
+
* call, so an over-long list costs a clear error instead of a provider 400
|
|
11
|
+
* on every call (retried, then reported as "tombstone budget exhausted", or
|
|
12
|
+
* for a fallback as "breaker open").
|
|
13
|
+
*
|
|
14
|
+
* The verdict is pure: the caller says which models can serve, how many
|
|
15
|
+
* tools each is sent and the environment the adapters read their endpoints
|
|
16
|
+
* from; the limits come from `@crewhaus/cost-tracker`, the table the
|
|
17
|
+
* compiler reads. An `openai/` model is held to api.openai.com's limit only
|
|
18
|
+
* when OPENAI_BASE_URL is unset or names api.openai.com — the compiler cannot
|
|
19
|
+
* see where it points, and leaves that to this check. The one piece of state
|
|
20
|
+
* is which boot lines this process has already written.
|
|
21
|
+
*/
|
|
22
|
+
import { type ToolLimitEnv } from "@crewhaus/cost-tracker";
|
|
23
|
+
/** One model that can be sent the run's tools, and how many it would be sent. */
|
|
24
|
+
export type ServingModel = {
|
|
25
|
+
readonly model: string;
|
|
26
|
+
readonly toolCount: number;
|
|
27
|
+
/**
|
|
28
|
+
* `serves` — the primary, a fallback, a tier or a pool candidate: a model
|
|
29
|
+
* the run's calls go to. `degrade` — the budget degrade rung, which serves
|
|
30
|
+
* only after spend, so it can never be the only way a run succeeds.
|
|
31
|
+
*/
|
|
32
|
+
readonly role: "serves" | "degrade";
|
|
33
|
+
/** How the boot line names it: "model_fallbacks[0] openai/gpt-4o", … */
|
|
34
|
+
readonly label: string;
|
|
35
|
+
/** What the run does about it when another model can serve: "routing leaves it out", … */
|
|
36
|
+
readonly whenOver: string;
|
|
37
|
+
};
|
|
38
|
+
export type ToolLimitVerdict = {
|
|
39
|
+
/** Set when no model that serves can accept its tools: the run cannot make one call. */
|
|
40
|
+
readonly fatal?: string;
|
|
41
|
+
/** One boot line per model over its limit, when some other model can serve. */
|
|
42
|
+
readonly warnings: ReadonlyArray<string>;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Check every serving model's tool count against its provider's per-request
|
|
46
|
+
* limit. `env` is where the adapters read their endpoints from: an `openai/`
|
|
47
|
+
* model that `OPENAI_BASE_URL` sends to another server is not held to
|
|
48
|
+
* api.openai.com's limit.
|
|
49
|
+
*/
|
|
50
|
+
export declare function checkServingToolLimits(serving: ReadonlyArray<ServingModel>, env?: ToolLimitEnv): ToolLimitVerdict;
|
|
51
|
+
/** The `lines` this process has not written yet, now marked as written. */
|
|
52
|
+
export declare function unreportedToolLimitLines(lines: ReadonlyArray<string>): string[];
|
|
53
|
+
/** Tests only: forget which boot lines were written. */
|
|
54
|
+
export declare function __resetToolLimitReportsForTests(): void;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* provider-limits#0 — the boot check of the run's tool list against the
|
|
3
|
+
* per-request limit of each model that can be sent it.
|
|
4
|
+
*
|
|
5
|
+
* The compiler checks the spec's builtin tools; this is the authoritative
|
|
6
|
+
* check, because only the running loop knows the full list: the builtins plus
|
|
7
|
+
* the loop's own tools (ListTools, continuity, memory, Task, Skill), MCP
|
|
8
|
+
* server tools, plugin tools and the hybrid pair — and a `crewhaus run
|
|
9
|
+
* --model` override the compiler never saw. It runs before the first model
|
|
10
|
+
* call, so an over-long list costs a clear error instead of a provider 400
|
|
11
|
+
* on every call (retried, then reported as "tombstone budget exhausted", or
|
|
12
|
+
* for a fallback as "breaker open").
|
|
13
|
+
*
|
|
14
|
+
* The verdict is pure: the caller says which models can serve, how many
|
|
15
|
+
* tools each is sent and the environment the adapters read their endpoints
|
|
16
|
+
* from; the limits come from `@crewhaus/cost-tracker`, the table the
|
|
17
|
+
* compiler reads. An `openai/` model is held to api.openai.com's limit only
|
|
18
|
+
* when OPENAI_BASE_URL is unset or names api.openai.com — the compiler cannot
|
|
19
|
+
* see where it points, and leaves that to this check. The one piece of state
|
|
20
|
+
* is which boot lines this process has already written.
|
|
21
|
+
*/
|
|
22
|
+
import { describeToolLimitOverrun, toolLimitOverrun, } from "@crewhaus/cost-tracker";
|
|
23
|
+
/**
|
|
24
|
+
* Check every serving model's tool count against its provider's per-request
|
|
25
|
+
* limit. `env` is where the adapters read their endpoints from: an `openai/`
|
|
26
|
+
* model that `OPENAI_BASE_URL` sends to another server is not held to
|
|
27
|
+
* api.openai.com's limit.
|
|
28
|
+
*/
|
|
29
|
+
export function checkServingToolLimits(serving, env = {}) {
|
|
30
|
+
const overruns = new Map();
|
|
31
|
+
for (const s of serving) {
|
|
32
|
+
const o = toolLimitOverrun(s.model, s.toolCount, env);
|
|
33
|
+
if (o !== undefined)
|
|
34
|
+
overruns.set(s, o);
|
|
35
|
+
}
|
|
36
|
+
if (overruns.size === 0)
|
|
37
|
+
return { warnings: [] };
|
|
38
|
+
const servers = serving.filter((s) => s.role === "serves");
|
|
39
|
+
const fix = "Narrow the tools (smaller all-<category> roll-ups, -<tool> exclusions, fewer MCP servers), or pick a model whose provider accepts more.";
|
|
40
|
+
if (servers.length > 0 && servers.every((s) => overruns.has(s))) {
|
|
41
|
+
const why = servers
|
|
42
|
+
.map((s) => describeToolLimitOverrun(overruns.get(s), "the run's tools"))
|
|
43
|
+
.join("; ");
|
|
44
|
+
return { fatal: `${why}. ${fix}`, warnings: [] };
|
|
45
|
+
}
|
|
46
|
+
const warnings = [...overruns].map(([s, o]) => `${s.label}: ${describeToolLimitOverrun(o, "the run's tools")}; ${s.whenOver}. ${fix}`);
|
|
47
|
+
return { warnings };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Boot lines this process has already written. A channel daemon, `managed`
|
|
51
|
+
* and `serve --mcp` run one loop per message or request, and the same
|
|
52
|
+
* verdict would otherwise be repeated on every one of them for the daemon's
|
|
53
|
+
* whole life.
|
|
54
|
+
*/
|
|
55
|
+
const reportedLines = new Set();
|
|
56
|
+
/** The `lines` this process has not written yet, now marked as written. */
|
|
57
|
+
export function unreportedToolLimitLines(lines) {
|
|
58
|
+
const fresh = lines.filter((line) => !reportedLines.has(line));
|
|
59
|
+
for (const line of fresh)
|
|
60
|
+
reportedLines.add(line);
|
|
61
|
+
return fresh;
|
|
62
|
+
}
|
|
63
|
+
/** Tests only: forget which boot lines were written. */
|
|
64
|
+
export function __resetToolLimitReportsForTests() {
|
|
65
|
+
reportedLines.clear();
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewhaus/runtime-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Minimal runtime imported by generated harness bundles",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
12
13
|
}
|
|
13
14
|
},
|
|
14
15
|
"scripts": {
|
|
@@ -16,47 +17,50 @@
|
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
19
|
"@anthropic-ai/sdk": "^0.96.0",
|
|
19
|
-
"@crewhaus/abort-controller": "0.
|
|
20
|
-
"@crewhaus/adapter-anthropic": "0.
|
|
21
|
-
"@crewhaus/agent-context-isolation": "0.
|
|
22
|
-
"@crewhaus/boundary-classifier": "0.
|
|
23
|
-
"@crewhaus/circuit-breaker": "0.
|
|
24
|
-
"@crewhaus/compaction-autocompact": "0.
|
|
25
|
-
"@crewhaus/compaction-curator": "0.
|
|
26
|
-
"@crewhaus/compaction-snip": "0.
|
|
27
|
-
"@crewhaus/cost-tracker": "0.
|
|
28
|
-
"@crewhaus/egress-classifier": "0.
|
|
29
|
-
"@crewhaus/errors": "0.
|
|
30
|
-
"@crewhaus/event-log": "0.
|
|
31
|
-
"@crewhaus/hooks-engine": "0.
|
|
32
|
-
"@crewhaus/metrics-collector": "0.
|
|
33
|
-
"@crewhaus/model-plan": "0.
|
|
34
|
-
"@crewhaus/model-router": "0.
|
|
35
|
-
"@crewhaus/otel-exporter": "0.
|
|
36
|
-
"@crewhaus/permission-engine": "0.
|
|
37
|
-
"@crewhaus/prompt-cache-manager": "0.
|
|
38
|
-
"@crewhaus/prompt-injection-detector": "0.
|
|
39
|
-
"@crewhaus/
|
|
40
|
-
"@crewhaus/
|
|
41
|
-
"@crewhaus/
|
|
42
|
-
"@crewhaus/
|
|
43
|
-
"@crewhaus/
|
|
44
|
-
"@crewhaus/
|
|
45
|
-
"@crewhaus/
|
|
46
|
-
"@crewhaus/
|
|
47
|
-
"@crewhaus/
|
|
48
|
-
"@crewhaus/
|
|
49
|
-
"@crewhaus/structured-event-printer": "0.
|
|
50
|
-
"@crewhaus/
|
|
51
|
-
"@crewhaus/
|
|
52
|
-
"@crewhaus/
|
|
53
|
-
"@crewhaus/tool-
|
|
54
|
-
"@crewhaus/tool-
|
|
55
|
-
"@crewhaus/tool-
|
|
56
|
-
"@crewhaus/tool-
|
|
57
|
-
"@crewhaus/
|
|
58
|
-
"@crewhaus/
|
|
59
|
-
"@crewhaus/
|
|
20
|
+
"@crewhaus/abort-controller": "0.8.0",
|
|
21
|
+
"@crewhaus/adapter-anthropic": "0.8.0",
|
|
22
|
+
"@crewhaus/agent-context-isolation": "0.8.0",
|
|
23
|
+
"@crewhaus/boundary-classifier": "0.8.0",
|
|
24
|
+
"@crewhaus/circuit-breaker": "0.8.0",
|
|
25
|
+
"@crewhaus/compaction-autocompact": "0.8.0",
|
|
26
|
+
"@crewhaus/compaction-curator": "0.8.0",
|
|
27
|
+
"@crewhaus/compaction-snip": "0.8.0",
|
|
28
|
+
"@crewhaus/cost-tracker": "0.8.0",
|
|
29
|
+
"@crewhaus/egress-classifier": "0.8.0",
|
|
30
|
+
"@crewhaus/errors": "0.8.0",
|
|
31
|
+
"@crewhaus/event-log": "0.8.0",
|
|
32
|
+
"@crewhaus/hooks-engine": "0.8.0",
|
|
33
|
+
"@crewhaus/metrics-collector": "0.8.0",
|
|
34
|
+
"@crewhaus/model-plan": "0.8.0",
|
|
35
|
+
"@crewhaus/model-router": "0.8.0",
|
|
36
|
+
"@crewhaus/otel-exporter": "0.8.0",
|
|
37
|
+
"@crewhaus/permission-engine": "0.8.0",
|
|
38
|
+
"@crewhaus/prompt-cache-manager": "0.8.0",
|
|
39
|
+
"@crewhaus/prompt-injection-detector": "0.8.0",
|
|
40
|
+
"@crewhaus/provability": "0.8.0",
|
|
41
|
+
"@crewhaus/rate-limiter": "0.8.0",
|
|
42
|
+
"@crewhaus/recovery-engine": "0.8.0",
|
|
43
|
+
"@crewhaus/routing-store": "0.8.0",
|
|
44
|
+
"@crewhaus/run-context": "0.8.0",
|
|
45
|
+
"@crewhaus/session-store": "0.8.0",
|
|
46
|
+
"@crewhaus/skills-registry": "0.8.0",
|
|
47
|
+
"@crewhaus/slash-commands": "0.8.0",
|
|
48
|
+
"@crewhaus/state-store": "0.8.0",
|
|
49
|
+
"@crewhaus/streaming-tool-executor": "0.8.0",
|
|
50
|
+
"@crewhaus/structured-event-printer": "0.8.0",
|
|
51
|
+
"@crewhaus/sub-agent-permission-inheritance": "0.8.0",
|
|
52
|
+
"@crewhaus/tenancy": "0.8.0",
|
|
53
|
+
"@crewhaus/token-budget": "0.8.0",
|
|
54
|
+
"@crewhaus/tool-catalog": "0.8.0",
|
|
55
|
+
"@crewhaus/tool-categories": "0.8.0",
|
|
56
|
+
"@crewhaus/tool-executor": "0.8.0",
|
|
57
|
+
"@crewhaus/tool-loop-detection": "0.8.0",
|
|
58
|
+
"@crewhaus/tool-orchestrator": "0.8.0",
|
|
59
|
+
"@crewhaus/tool-result-store": "0.8.0",
|
|
60
|
+
"@crewhaus/tool-safety": "0.8.0",
|
|
61
|
+
"@crewhaus/trace-event-bus": "0.8.0",
|
|
62
|
+
"@crewhaus/turn-state-machine": "0.8.0",
|
|
63
|
+
"@crewhaus/worker-runtime": "0.8.0",
|
|
60
64
|
"zod": "^3.23.8",
|
|
61
65
|
"zod-to-json-schema": "^3.23.5"
|
|
62
66
|
},
|
|
@@ -83,5 +87,8 @@
|
|
|
83
87
|
"publishConfig": {
|
|
84
88
|
"access": "public"
|
|
85
89
|
},
|
|
86
|
-
"files": ["dist", "README.md", "LICENSE", "NOTICE"]
|
|
90
|
+
"files": ["dist", "README.md", "LICENSE", "NOTICE"],
|
|
91
|
+
"engines": {
|
|
92
|
+
"bun": ">=1.3.14"
|
|
93
|
+
}
|
|
87
94
|
}
|