osuite 2.10.2 → 2.11.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/GOVERNED_TOOLS.md +202 -0
- package/README.md +17 -11
- package/governed-tools/authority.mjs +134 -0
- package/governed-tools/contract.mjs +142 -0
- package/governed-tools/examples/native-client.mjs +47 -0
- package/governed-tools/executor.mjs +185 -0
- package/governed-tools/journal.mjs +448 -0
- package/governed-tools/mcp.mjs +95 -0
- package/governed-tools.mjs +10 -0
- package/package.json +8 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { types } from 'node:util';
|
|
2
|
+
import { safeId } from '../runtime/protocol.mjs';
|
|
3
|
+
import { GovernedToolError, jsonSnapshot, reject } from './contract.mjs';
|
|
4
|
+
|
|
5
|
+
const boundedId = value => safeId(value) && value.length <= 128;
|
|
6
|
+
const signalAborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted').get;
|
|
7
|
+
|
|
8
|
+
function method(receiver, name) {
|
|
9
|
+
// SDK class methods may be inherited; never invoke getters or proxy traps.
|
|
10
|
+
let current = receiver;
|
|
11
|
+
for (let depth = 0; current != null && depth < 16; depth++) {
|
|
12
|
+
if (!['object', 'function'].includes(typeof current) || types.isProxy(current)) reject('INVALID_CONFIGURATION');
|
|
13
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, name);
|
|
14
|
+
if (descriptor) {
|
|
15
|
+
if (!Object.hasOwn(descriptor, 'value') || typeof descriptor.value !== 'function'
|
|
16
|
+
|| types.isProxy(descriptor.value)) reject('INVALID_CONFIGURATION');
|
|
17
|
+
return descriptor.value;
|
|
18
|
+
}
|
|
19
|
+
current = Object.getPrototypeOf(current);
|
|
20
|
+
}
|
|
21
|
+
reject('INVALID_CONFIGURATION');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function paramsSnapshot(params) {
|
|
25
|
+
const native = jsonSnapshot(params, 32768);
|
|
26
|
+
if (!native || typeof native !== 'object' || Array.isArray(native)
|
|
27
|
+
|| !Object.hasOwn(native, 'name') || !boundedId(native.name) || !Object.hasOwn(native, 'arguments')
|
|
28
|
+
|| !native.arguments || typeof native.arguments !== 'object' || Array.isArray(native.arguments)
|
|
29
|
+
|| Object.keys(native).some(key => key !== 'name' && key !== 'arguments')) reject('INVALID_INPUT');
|
|
30
|
+
return native;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isAborted(signal) {
|
|
34
|
+
if (!signal || typeof signal !== 'object' || types.isProxy(signal)) reject('INVALID_OPTIONS');
|
|
35
|
+
// Use the native brand check rather than reading caller-controlled .aborted.
|
|
36
|
+
try { return Reflect.apply(signalAborted, signal, []); } catch { reject('INVALID_OPTIONS'); }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function optionsSnapshot(options) {
|
|
40
|
+
if (options === undefined) return undefined;
|
|
41
|
+
if (!options || typeof options !== 'object' || types.isProxy(options)) reject('INVALID_OPTIONS');
|
|
42
|
+
const prototype = Object.getPrototypeOf(options);
|
|
43
|
+
if (prototype !== Object.prototype && prototype !== null) reject('INVALID_OPTIONS');
|
|
44
|
+
const descriptors = Object.getOwnPropertyDescriptors(options);
|
|
45
|
+
const safeOptions = {};
|
|
46
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
47
|
+
const descriptor = descriptors[key];
|
|
48
|
+
if ((key !== 'signal' && key !== 'timeout') || !descriptor.enumerable
|
|
49
|
+
|| !Object.hasOwn(descriptor, 'value')) reject('INVALID_OPTIONS');
|
|
50
|
+
const value = descriptor.value;
|
|
51
|
+
if (key === 'signal') isAborted(value);
|
|
52
|
+
else if (!Number.isInteger(value) || value < 1 || value > 30000) reject('INVALID_OPTIONS');
|
|
53
|
+
safeOptions[key] = value;
|
|
54
|
+
}
|
|
55
|
+
return Object.freeze(safeOptions);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function coordinatorError(error) {
|
|
59
|
+
let governed = false;
|
|
60
|
+
try { governed = !types.isProxy(error) && error instanceof GovernedToolError; } catch { /* Untrusted thrown values stay opaque. */ }
|
|
61
|
+
if (governed) throw error;
|
|
62
|
+
reject('UNCERTAIN');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Bounded MCP profile: required record arguments and safeId tool names (1..128, no '..').
|
|
66
|
+
// Not arbitrary all-MCP compatibility; covers only wrapped calls, not a production gateway.
|
|
67
|
+
export function wrapMcpClient(client, tools) {
|
|
68
|
+
const originalCallTool = method(client, 'callTool');
|
|
69
|
+
const originalRun = method(tools, 'run');
|
|
70
|
+
const originalStatus = method(tools, 'status');
|
|
71
|
+
return Object.freeze({
|
|
72
|
+
operation(operationId) {
|
|
73
|
+
if (!boundedId(operationId)) reject('INVALID_OPERATION_ID');
|
|
74
|
+
return Object.freeze({
|
|
75
|
+
async callTool(params, resultSchema, options) {
|
|
76
|
+
const native = paramsSnapshot(params);
|
|
77
|
+
const safeOptions = optionsSnapshot(options);
|
|
78
|
+
const signal = safeOptions?.signal;
|
|
79
|
+
if (signal && isAborted(signal)) reject('ABORTED');
|
|
80
|
+
// Native timeout is not the coordinator's approval wait budget.
|
|
81
|
+
const runOptions = Object.freeze(signal ? { signal } : {});
|
|
82
|
+
try {
|
|
83
|
+
return await Reflect.apply(originalRun, tools, [operationId, native,
|
|
84
|
+
p => Reflect.apply(originalCallTool, client, [p, resultSchema, safeOptions]), runOptions]);
|
|
85
|
+
} catch (error) { coordinatorError(error); }
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
async status(operationId) {
|
|
90
|
+
if (!boundedId(operationId)) reject('INVALID_OPERATION_ID');
|
|
91
|
+
try { return await Reflect.apply(originalStatus, tools, [operationId]); }
|
|
92
|
+
catch (error) { coordinatorError(error); }
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GovernedToolError } from './governed-tools/contract.mjs';
|
|
2
|
+
|
|
3
|
+
if (Number(process.versions.node.split('.')[0]) !== 24) {
|
|
4
|
+
throw new GovernedToolError('NODE_24_REQUIRED');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// Delay the SQLite import until after the explicit runtime compatibility check.
|
|
8
|
+
export const { createGovernedTools } = await import('./governed-tools/executor.mjs');
|
|
9
|
+
export const { wrapMcpClient } = await import('./governed-tools/mcp.mjs');
|
|
10
|
+
export { GovernedToolError };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "osuite",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "OSuite governed action SDK for AI agents. Approve, replay, prove, and verify runtime decisions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"./legacy": {
|
|
20
20
|
"import": "./legacy/osuite-v1.js",
|
|
21
21
|
"require": "./legacy/index-v1.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./governed-tools": {
|
|
24
|
+
"import": "./governed-tools.mjs"
|
|
22
25
|
}
|
|
23
26
|
},
|
|
24
27
|
"files": [
|
|
@@ -29,6 +32,10 @@
|
|
|
29
32
|
"tryFlow.js",
|
|
30
33
|
"tryContract.js",
|
|
31
34
|
"runtime/",
|
|
35
|
+
"governed-tools.mjs",
|
|
36
|
+
"governed-tools/*.mjs",
|
|
37
|
+
"governed-tools/examples/*.mjs",
|
|
38
|
+
"GOVERNED_TOOLS.md",
|
|
32
39
|
"projectHooks.js",
|
|
33
40
|
"reviewSurface.js",
|
|
34
41
|
"osuite.js",
|