@crewhaus/tool-proof 0.0.0-stage → 0.8.1
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 +149 -2
- package/dist/index.d.ts +148 -0
- package/dist/index.js +365 -0
- package/dist/lib/check.d.ts +122 -0
- package/dist/lib/check.js +260 -0
- package/dist/lib/checkers.d.ts +62 -0
- package/dist/lib/checkers.js +136 -0
- package/dist/lib/config.d.ts +39 -0
- package/dist/lib/config.js +71 -0
- package/dist/lib/context.d.ts +57 -0
- package/dist/lib/context.js +52 -0
- package/dist/lib/evidence.d.ts +57 -0
- package/dist/lib/evidence.js +173 -0
- package/dist/lib/preflight.d.ts +87 -0
- package/dist/lib/preflight.js +196 -0
- package/dist/lib/recheck.d.ts +31 -0
- package/dist/lib/recheck.js +47 -0
- package/dist/lib/roots.d.ts +44 -0
- package/dist/lib/roots.js +105 -0
- package/package.json +55 -4
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Tenant } from "@crewhaus/tenancy";
|
|
2
|
+
/** A tenant's own root: the parent of its sessions, state and tool results. */
|
|
3
|
+
export declare function tenantRootOf(tenant: Tenant): string;
|
|
4
|
+
/**
|
|
5
|
+
* The proofs root for `specName`: `<tenantRoot>/proofs/<spec>` under a
|
|
6
|
+
* tenant, `<workspaceRoot>/.crewhaus/proofs/<spec>` otherwise. The spec
|
|
7
|
+
* name is checked by provability's rule either way.
|
|
8
|
+
*/
|
|
9
|
+
export declare function defaultProofsRoot(workspaceRoot: string, specName: string, tenant: Tenant | undefined): string;
|
|
10
|
+
/**
|
|
11
|
+
* The session-log root a preflight reads when nobody named one: the active
|
|
12
|
+
* tenant's `sessionRoot`, else `CREWHAUS_SESSION_DIR` — runtime-core's
|
|
13
|
+
* `resolveSessionRootDir` order, so the tools read where the runtime wrote.
|
|
14
|
+
* Undefined leaves event-log's default (`.crewhaus/sessions`).
|
|
15
|
+
*/
|
|
16
|
+
export declare function defaultSessionRoot(tenant: Tenant | undefined): string | undefined;
|
|
17
|
+
/** `dir`, resolved, after checking it lies inside the active tenant's root (when there is one). */
|
|
18
|
+
export declare function fenced(dir: string, tenant: Tenant | undefined): string;
|
|
19
|
+
/**
|
|
20
|
+
* Environment variables that relocate the runtime's own state: sessions,
|
|
21
|
+
* datasets, watch-me records, the shared directory and the tenants' roots.
|
|
22
|
+
*/
|
|
23
|
+
export declare const STATE_ENV_VARS: ReadonlyArray<string>;
|
|
24
|
+
/**
|
|
25
|
+
* The directories, beyond the workspace's `.crewhaus/`, where this run keeps
|
|
26
|
+
* its own record — the verifier's `VerifyOptions.stateRoots` (design §1
|
|
27
|
+
* principle 1: evidence is a source the run read, never what the model
|
|
28
|
+
* said). A session log holds every answer verbatim, a bundle every claim, a
|
|
29
|
+
* spilled result what a tool returned; read back and cited, each grounds the
|
|
30
|
+
* model's own text. So a path under the session root the gate reads, the
|
|
31
|
+
* proofs root, the active tenant's root and spill root, or a directory an
|
|
32
|
+
* environment variable relocated state to, is no source. The gate and the
|
|
33
|
+
* preflight read the same list, so they agree (design §6).
|
|
34
|
+
*
|
|
35
|
+
* A directory that holds the workspace itself is left out: refusing it
|
|
36
|
+
* would refuse every file the run read.
|
|
37
|
+
*/
|
|
38
|
+
export declare function runtimeStateRoots(input: {
|
|
39
|
+
readonly workspaceRoot: string;
|
|
40
|
+
readonly sessionRootDir?: string;
|
|
41
|
+
readonly proofsRoot?: string;
|
|
42
|
+
readonly tenant?: Tenant;
|
|
43
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
44
|
+
}): string[];
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the proof tools file artifacts and read session logs, tenant-aware
|
|
3
|
+
* (design §5.3, §8: proofs are tenant-fenced on the managed shape).
|
|
4
|
+
*
|
|
5
|
+
* Outside a tenant scope the proofs root is provability's
|
|
6
|
+
* `proofsRoot(workspaceRoot, spec)`, `<cwd>/.crewhaus/proofs/<spec>`. Every
|
|
7
|
+
* managed turn runs inside its request's `withTenant`, and there the
|
|
8
|
+
* tenant's root stands where `.crewhaus/` does: `<tenantRoot>/proofs/<spec>`,
|
|
9
|
+
* beside the tenant's sessions, tool results and state. One tenant's claims,
|
|
10
|
+
* statements and proofs then never share a directory with another's, and a
|
|
11
|
+
* preflight reads only its own tenant's artifacts. The tenant's root is the
|
|
12
|
+
* parent of its `sessionRoot`, the rule continuity-store and wiki-store
|
|
13
|
+
* fence by.
|
|
14
|
+
*
|
|
15
|
+
* Under a tenant, any root the tools would use — a caller's explicit
|
|
16
|
+
* `proofsRoot` or `sessionRootDir` included — that resolves outside the
|
|
17
|
+
* tenant's root fails closed (`TenancyError`, CWE-1230), as every
|
|
18
|
+
* tenant-aware store does. A tools instance built once with a fixed root
|
|
19
|
+
* and shared by every tenant would otherwise pool them all.
|
|
20
|
+
*/
|
|
21
|
+
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
22
|
+
import { proofsRoot } from "@crewhaus/provability";
|
|
23
|
+
import { assertSamePath } from "@crewhaus/tenancy";
|
|
24
|
+
/** A tenant's own root: the parent of its sessions, state and tool results. */
|
|
25
|
+
export function tenantRootOf(tenant) {
|
|
26
|
+
return resolve(tenant.sessionRoot, "..");
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The proofs root for `specName`: `<tenantRoot>/proofs/<spec>` under a
|
|
30
|
+
* tenant, `<workspaceRoot>/.crewhaus/proofs/<spec>` otherwise. The spec
|
|
31
|
+
* name is checked by provability's rule either way.
|
|
32
|
+
*/
|
|
33
|
+
export function defaultProofsRoot(workspaceRoot, specName, tenant) {
|
|
34
|
+
const plain = proofsRoot(workspaceRoot, specName);
|
|
35
|
+
return tenant === undefined ? plain : join(tenantRootOf(tenant), "proofs", specName);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The session-log root a preflight reads when nobody named one: the active
|
|
39
|
+
* tenant's `sessionRoot`, else `CREWHAUS_SESSION_DIR` — runtime-core's
|
|
40
|
+
* `resolveSessionRootDir` order, so the tools read where the runtime wrote.
|
|
41
|
+
* Undefined leaves event-log's default (`.crewhaus/sessions`).
|
|
42
|
+
*/
|
|
43
|
+
export function defaultSessionRoot(tenant) {
|
|
44
|
+
if (tenant !== undefined)
|
|
45
|
+
return tenant.sessionRoot;
|
|
46
|
+
const fromEnv = process.env["CREWHAUS_SESSION_DIR"];
|
|
47
|
+
return fromEnv !== undefined && fromEnv !== "" ? fromEnv : undefined;
|
|
48
|
+
}
|
|
49
|
+
/** `dir`, resolved, after checking it lies inside the active tenant's root (when there is one). */
|
|
50
|
+
export function fenced(dir, tenant) {
|
|
51
|
+
const abs = resolve(dir);
|
|
52
|
+
if (tenant !== undefined)
|
|
53
|
+
assertSamePath(abs, tenantRootOf(tenant));
|
|
54
|
+
return abs;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Environment variables that relocate the runtime's own state: sessions,
|
|
58
|
+
* datasets, watch-me records, the shared directory and the tenants' roots.
|
|
59
|
+
*/
|
|
60
|
+
export const STATE_ENV_VARS = [
|
|
61
|
+
"CREWHAUS_SESSION_DIR",
|
|
62
|
+
"CREWHAUS_DATASETS_DIR",
|
|
63
|
+
"CREWHAUS_WATCHME_ROOT",
|
|
64
|
+
"CREWHAUS_SHARED_DIR",
|
|
65
|
+
"CREWHAUS_TENANTS_ROOT",
|
|
66
|
+
];
|
|
67
|
+
/**
|
|
68
|
+
* The directories, beyond the workspace's `.crewhaus/`, where this run keeps
|
|
69
|
+
* its own record — the verifier's `VerifyOptions.stateRoots` (design §1
|
|
70
|
+
* principle 1: evidence is a source the run read, never what the model
|
|
71
|
+
* said). A session log holds every answer verbatim, a bundle every claim, a
|
|
72
|
+
* spilled result what a tool returned; read back and cited, each grounds the
|
|
73
|
+
* model's own text. So a path under the session root the gate reads, the
|
|
74
|
+
* proofs root, the active tenant's root and spill root, or a directory an
|
|
75
|
+
* environment variable relocated state to, is no source. The gate and the
|
|
76
|
+
* preflight read the same list, so they agree (design §6).
|
|
77
|
+
*
|
|
78
|
+
* A directory that holds the workspace itself is left out: refusing it
|
|
79
|
+
* would refuse every file the run read.
|
|
80
|
+
*/
|
|
81
|
+
export function runtimeStateRoots(input) {
|
|
82
|
+
const env = input.env ?? process.env;
|
|
83
|
+
const workspace = resolve(input.workspaceRoot);
|
|
84
|
+
const named = [
|
|
85
|
+
input.sessionRootDir,
|
|
86
|
+
input.proofsRoot,
|
|
87
|
+
...(input.tenant !== undefined
|
|
88
|
+
? [input.tenant.toolResultRoot, tenantRootOf(input.tenant)]
|
|
89
|
+
: []),
|
|
90
|
+
...STATE_ENV_VARS.map((name) => env[name]),
|
|
91
|
+
];
|
|
92
|
+
const out = [];
|
|
93
|
+
for (const dir of named) {
|
|
94
|
+
if (dir === undefined || dir.trim() === "")
|
|
95
|
+
continue;
|
|
96
|
+
const abs = resolve(workspace, dir);
|
|
97
|
+
const up = relative(abs, workspace);
|
|
98
|
+
// The workspace is the directory or under it.
|
|
99
|
+
if (up === "" || (!up.startsWith("..") && !isAbsolute(up)))
|
|
100
|
+
continue;
|
|
101
|
+
if (!out.includes(abs))
|
|
102
|
+
out.push(abs);
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewhaus/tool-proof",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.8.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "ProofCheckers, ProofCheck and ProvabilityPreflight: the tools a harness uses to prove claims and check a draft before it answers",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "bun test src"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@crewhaus/errors": "0.8.1",
|
|
20
|
+
"@crewhaus/event-log": "0.8.1",
|
|
21
|
+
"@crewhaus/proof-checker": "0.8.1",
|
|
22
|
+
"@crewhaus/provability": "0.8.1",
|
|
23
|
+
"@crewhaus/sandbox": "0.8.1",
|
|
24
|
+
"@crewhaus/tenancy": "0.8.1",
|
|
25
|
+
"@crewhaus/tool-builder": "0.8.1",
|
|
26
|
+
"@crewhaus/tool-catalog": "0.8.1",
|
|
27
|
+
"@crewhaus/tool-categories": "0.8.1",
|
|
28
|
+
"@crewhaus/trace-event-bus": "0.8.1",
|
|
29
|
+
"zod": "^3.23.8"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@crewhaus/tool-executor": "workspace:*",
|
|
33
|
+
"@crewhaus/tool-result-store": "workspace:*"
|
|
34
|
+
},
|
|
35
|
+
"license": "Apache-2.0",
|
|
36
|
+
"author": {
|
|
37
|
+
"name": "Max Meier",
|
|
38
|
+
"email": "max@crewhaus.ai",
|
|
39
|
+
"url": "https://crewhaus.ai"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/crewhaus/factory.git",
|
|
44
|
+
"directory": "packages/tool-proof"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/crewhaus/factory/tree/main/packages/tool-proof#readme",
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/crewhaus/factory/issues"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"files": ["dist", "README.md", "LICENSE", "NOTICE"],
|
|
54
|
+
"engines": {
|
|
55
|
+
"bun": ">=1.3.14"
|
|
56
|
+
}
|
|
57
|
+
}
|