@neuroverseos/governance 0.2.3 → 0.3.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/package.json +4 -2
- package/policies/content-moderation-rules.txt +8 -0
- package/policies/marketing-rules.txt +8 -0
- package/policies/science-research-rules.txt +11 -0
- package/policies/social-media-rules.txt +7 -0
- package/policies/strict-rules.txt +8 -0
- package/policies/trading-rules.txt +8 -0
- package/simulate.html +1899 -0
- package/dist/adapters/autoresearch.cjs +0 -196
- package/dist/adapters/autoresearch.d.cts +0 -103
- package/dist/adapters/autoresearch.d.ts +0 -103
- package/dist/adapters/autoresearch.js +0 -7
- package/dist/adapters/deep-agents.cjs +0 -1472
- package/dist/adapters/deep-agents.d.cts +0 -181
- package/dist/adapters/deep-agents.d.ts +0 -181
- package/dist/adapters/deep-agents.js +0 -17
- package/dist/adapters/express.cjs +0 -1196
- package/dist/adapters/express.d.cts +0 -66
- package/dist/adapters/express.d.ts +0 -66
- package/dist/adapters/express.js +0 -12
- package/dist/adapters/index.cjs +0 -2038
- package/dist/adapters/index.d.cts +0 -8
- package/dist/adapters/index.d.ts +0 -8
- package/dist/adapters/index.js +0 -68
- package/dist/adapters/langchain.cjs +0 -1259
- package/dist/adapters/langchain.d.cts +0 -89
- package/dist/adapters/langchain.d.ts +0 -89
- package/dist/adapters/langchain.js +0 -17
- package/dist/adapters/openai.cjs +0 -1289
- package/dist/adapters/openai.d.cts +0 -99
- package/dist/adapters/openai.d.ts +0 -99
- package/dist/adapters/openai.js +0 -17
- package/dist/adapters/openclaw.cjs +0 -1281
- package/dist/adapters/openclaw.d.cts +0 -99
- package/dist/adapters/openclaw.d.ts +0 -99
- package/dist/adapters/openclaw.js +0 -17
- package/dist/bootstrap-GXVDZNF7.js +0 -114
- package/dist/build-X5MZY4IA.js +0 -339
- package/dist/chunk-4L6OPKMQ.js +0 -100
- package/dist/chunk-4NGDRRQH.js +0 -10
- package/dist/chunk-5U2MQO5P.js +0 -57
- package/dist/chunk-6BB55YJI.js +0 -113
- package/dist/chunk-6CZSKEY5.js +0 -164
- package/dist/chunk-7P3S7MAY.js +0 -1090
- package/dist/chunk-A5W4GNQO.js +0 -130
- package/dist/chunk-AF2VX4AL.js +0 -363
- package/dist/chunk-AKW5YVCE.js +0 -96
- package/dist/chunk-BMOXICAB.js +0 -340
- package/dist/chunk-BQZMOEML.js +0 -43
- package/dist/chunk-D2UCV5AK.js +0 -326
- package/dist/chunk-EVDJUSZ2.js +0 -91
- package/dist/chunk-FYS2CBUW.js +0 -304
- package/dist/chunk-I3RRAYK2.js +0 -11
- package/dist/chunk-IZSO75NZ.js +0 -792
- package/dist/chunk-JCKSW2PZ.js +0 -304
- package/dist/chunk-JZPQGIKR.js +0 -79
- package/dist/chunk-KTFTTLTP.js +0 -246
- package/dist/chunk-MH7BT4VH.js +0 -15
- package/dist/chunk-ORJ3NOE6.js +0 -622
- package/dist/chunk-OT6PXH54.js +0 -61
- package/dist/chunk-Q6O7ZLO2.js +0 -62
- package/dist/chunk-QLPTHTVB.js +0 -253
- package/dist/chunk-REXY4LUL.js +0 -226
- package/dist/chunk-T5EUJQE5.js +0 -172
- package/dist/chunk-TTBKTF3P.js +0 -608
- package/dist/chunk-XPDMYECO.js +0 -642
- package/dist/chunk-YZFATT7X.js +0 -9
- package/dist/chunk-ZIVQNSZU.js +0 -119
- package/dist/chunk-ZJTDUCC2.js +0 -194
- package/dist/cli/neuroverse.cjs +0 -12564
- package/dist/cli/neuroverse.d.cts +0 -1
- package/dist/cli/neuroverse.d.ts +0 -1
- package/dist/cli/neuroverse.js +0 -208
- package/dist/cli/plan.cjs +0 -1686
- package/dist/cli/plan.d.cts +0 -20
- package/dist/cli/plan.d.ts +0 -20
- package/dist/cli/plan.js +0 -353
- package/dist/cli/run.cjs +0 -1945
- package/dist/cli/run.d.cts +0 -20
- package/dist/cli/run.d.ts +0 -20
- package/dist/cli/run.js +0 -143
- package/dist/configure-ai-TK67ZWZL.js +0 -132
- package/dist/decision-flow-LETV5NWY.js +0 -61
- package/dist/derive-7365SUFU.js +0 -152
- package/dist/doctor-QYISMKEL.js +0 -173
- package/dist/equity-penalties-63FGB3I2.js +0 -244
- package/dist/explain-A2EWI2OL.js +0 -51
- package/dist/guard-3BWL3IGH.js +0 -92
- package/dist/guard-contract-C9_zKbzd.d.cts +0 -821
- package/dist/guard-contract-C9_zKbzd.d.ts +0 -821
- package/dist/guard-engine-QFMIBWJY.js +0 -10
- package/dist/impact-UB6DXKSX.js +0 -59
- package/dist/improve-XZA57GER.js +0 -66
- package/dist/index.cjs +0 -6821
- package/dist/index.d.cts +0 -1829
- package/dist/index.d.ts +0 -1829
- package/dist/index.js +0 -430
- package/dist/infer-world-7GVZWFX4.js +0 -543
- package/dist/init-PKPIYHYE.js +0 -144
- package/dist/init-world-VWMQZQC7.js +0 -223
- package/dist/mcp-server-XWQZXNW7.js +0 -13
- package/dist/model-adapter-BB7G4MFI.js +0 -11
- package/dist/playground-ADWZORNV.js +0 -550
- package/dist/redteam-JRQ7FD2F.js +0 -357
- package/dist/session-MMYX5YCF.js +0 -15
- package/dist/shared--Q8wPBVN.d.ts +0 -60
- package/dist/shared-HpAG90PX.d.cts +0 -60
- package/dist/shared-U2QFV7JH.js +0 -16
- package/dist/simulate-GMIFFXYV.js +0 -83
- package/dist/test-JBBZ65X4.js +0 -217
- package/dist/trace-3MYWIDEF.js +0 -166
- package/dist/validate-LLBWVPGV.js +0 -81
- package/dist/validate-engine-UIABSIHD.js +0 -7
- package/dist/world-BFJCIQSH.js +0 -378
- package/dist/world-loader-HMPTOEA2.js +0 -9
- package/dist/worlds/autoresearch.nv-world.md +0 -230
- package/dist/worlds/coding-agent.nv-world.md +0 -211
- package/dist/worlds/derivation-world.nv-world.md +0 -278
package/dist/chunk-4L6OPKMQ.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
evaluateGuard
|
|
3
|
-
} from "./chunk-IZSO75NZ.js";
|
|
4
|
-
import {
|
|
5
|
-
loadWorld
|
|
6
|
-
} from "./chunk-JZPQGIKR.js";
|
|
7
|
-
|
|
8
|
-
// src/adapters/express.ts
|
|
9
|
-
function methodToCategory(method) {
|
|
10
|
-
switch (method.toUpperCase()) {
|
|
11
|
-
case "GET":
|
|
12
|
-
case "HEAD":
|
|
13
|
-
case "OPTIONS":
|
|
14
|
-
return "read";
|
|
15
|
-
case "POST":
|
|
16
|
-
case "PUT":
|
|
17
|
-
case "PATCH":
|
|
18
|
-
return "write";
|
|
19
|
-
case "DELETE":
|
|
20
|
-
return "delete";
|
|
21
|
-
default:
|
|
22
|
-
return "other";
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function defaultMapRequest(req) {
|
|
26
|
-
const method = (req.method ?? "GET").toUpperCase();
|
|
27
|
-
const path = req.path ?? req.url ?? "/";
|
|
28
|
-
return {
|
|
29
|
-
intent: `${method} ${path}`,
|
|
30
|
-
tool: "http",
|
|
31
|
-
scope: path,
|
|
32
|
-
actionCategory: methodToCategory(method),
|
|
33
|
-
direction: "input",
|
|
34
|
-
args: {
|
|
35
|
-
method,
|
|
36
|
-
path,
|
|
37
|
-
...req.params ?? {},
|
|
38
|
-
...req.query ?? {}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function defaultOnBlock(verdict, _req, res, statusCode) {
|
|
43
|
-
const body = {
|
|
44
|
-
error: "Governance policy violation",
|
|
45
|
-
reason: verdict.reason ?? "Action not permitted",
|
|
46
|
-
ruleId: verdict.ruleId,
|
|
47
|
-
status: verdict.status
|
|
48
|
-
};
|
|
49
|
-
if (res.status && res.json) {
|
|
50
|
-
res.status(statusCode).json(body);
|
|
51
|
-
} else if (res.send) {
|
|
52
|
-
res.statusCode = statusCode;
|
|
53
|
-
res.send(JSON.stringify(body));
|
|
54
|
-
} else if (res.end) {
|
|
55
|
-
res.statusCode = statusCode;
|
|
56
|
-
res.end();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async function createGovernanceMiddleware(worldPath, options) {
|
|
60
|
-
const world = await loadWorld(worldPath);
|
|
61
|
-
return createGovernanceMiddlewareFromWorld(world, options);
|
|
62
|
-
}
|
|
63
|
-
function createGovernanceMiddlewareFromWorld(world, options = {}) {
|
|
64
|
-
const engineOptions = {
|
|
65
|
-
trace: options.trace ?? false,
|
|
66
|
-
level: options.level
|
|
67
|
-
};
|
|
68
|
-
const mapRequest = options.mapRequest ?? defaultMapRequest;
|
|
69
|
-
const blockStatusCode = options.blockStatusCode ?? 403;
|
|
70
|
-
return async function neuroVerseGovernance(req, res, next) {
|
|
71
|
-
try {
|
|
72
|
-
const event = mapRequest(req);
|
|
73
|
-
const verdict = evaluateGuard(event, world, engineOptions);
|
|
74
|
-
options.onEvaluate?.(verdict, event, req);
|
|
75
|
-
if (verdict.status === "ALLOW") {
|
|
76
|
-
next();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (verdict.status === "PAUSE") {
|
|
80
|
-
const approved = await options.onPause?.(verdict, req);
|
|
81
|
-
if (approved) {
|
|
82
|
-
next();
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (options.onBlock) {
|
|
87
|
-
options.onBlock(verdict, req, res);
|
|
88
|
-
} else {
|
|
89
|
-
defaultOnBlock(verdict, req, res, blockStatusCode);
|
|
90
|
-
}
|
|
91
|
-
} catch (err) {
|
|
92
|
-
next(err);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export {
|
|
98
|
-
createGovernanceMiddleware,
|
|
99
|
-
createGovernanceMiddlewareFromWorld
|
|
100
|
-
};
|
package/dist/chunk-4NGDRRQH.js
DELETED
package/dist/chunk-5U2MQO5P.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
advancePlan,
|
|
3
|
-
evaluatePlan,
|
|
4
|
-
getPlanProgress
|
|
5
|
-
} from "./chunk-QLPTHTVB.js";
|
|
6
|
-
|
|
7
|
-
// src/adapters/shared.ts
|
|
8
|
-
var GovernanceBlockedError = class extends Error {
|
|
9
|
-
verdict;
|
|
10
|
-
constructor(verdict, message) {
|
|
11
|
-
super(message ?? `[NeuroVerse] BLOCKED: ${verdict.reason ?? verdict.ruleId ?? "governance rule"}`);
|
|
12
|
-
this.name = "GovernanceBlockedError";
|
|
13
|
-
this.verdict = verdict;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
function trackPlanProgress(event, state, callbacks) {
|
|
17
|
-
if (!state.activePlan) return;
|
|
18
|
-
const planVerdict = evaluatePlan(event, state.activePlan);
|
|
19
|
-
if (planVerdict.matchedStep) {
|
|
20
|
-
const advResult = advancePlan(state.activePlan, planVerdict.matchedStep);
|
|
21
|
-
if (advResult.success && advResult.plan) {
|
|
22
|
-
state.activePlan = advResult.plan;
|
|
23
|
-
state.engineOptions.plan = state.activePlan;
|
|
24
|
-
}
|
|
25
|
-
const progress = getPlanProgress(state.activePlan);
|
|
26
|
-
callbacks.onPlanProgress?.(progress);
|
|
27
|
-
if (progress.completed === progress.total) {
|
|
28
|
-
callbacks.onPlanComplete?.();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function extractScope(args) {
|
|
33
|
-
if (typeof args.path === "string") return args.path;
|
|
34
|
-
if (typeof args.file_path === "string") return args.file_path;
|
|
35
|
-
if (typeof args.filename === "string") return args.filename;
|
|
36
|
-
if (typeof args.url === "string") return args.url;
|
|
37
|
-
if (typeof args.command === "string") return args.command;
|
|
38
|
-
return void 0;
|
|
39
|
-
}
|
|
40
|
-
function buildEngineOptions(options, plan) {
|
|
41
|
-
return {
|
|
42
|
-
trace: options.trace ?? false,
|
|
43
|
-
level: options.level,
|
|
44
|
-
plan: plan ?? options.plan
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function defaultBlockMessage(verdict) {
|
|
48
|
-
return `Action blocked by governance policy: ${verdict.reason ?? "rule violation"}. Rule: ${verdict.ruleId ?? "unknown"}.`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export {
|
|
52
|
-
GovernanceBlockedError,
|
|
53
|
-
trackPlanProgress,
|
|
54
|
-
extractScope,
|
|
55
|
-
buildEngineOptions,
|
|
56
|
-
defaultBlockMessage
|
|
57
|
-
};
|
package/dist/chunk-6BB55YJI.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GovernanceBlockedError,
|
|
3
|
-
buildEngineOptions,
|
|
4
|
-
extractScope,
|
|
5
|
-
trackPlanProgress
|
|
6
|
-
} from "./chunk-5U2MQO5P.js";
|
|
7
|
-
import {
|
|
8
|
-
evaluateGuard
|
|
9
|
-
} from "./chunk-IZSO75NZ.js";
|
|
10
|
-
import {
|
|
11
|
-
loadWorld
|
|
12
|
-
} from "./chunk-JZPQGIKR.js";
|
|
13
|
-
|
|
14
|
-
// src/adapters/openclaw.ts
|
|
15
|
-
var GovernanceBlockedError2 = class extends GovernanceBlockedError {
|
|
16
|
-
action;
|
|
17
|
-
constructor(verdict, action) {
|
|
18
|
-
super(verdict);
|
|
19
|
-
this.action = action;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
function defaultMapAction(action, direction) {
|
|
23
|
-
return {
|
|
24
|
-
intent: action.type,
|
|
25
|
-
tool: action.tool ?? action.type,
|
|
26
|
-
args: action.input,
|
|
27
|
-
direction,
|
|
28
|
-
scope: action.input ? extractScope(action.input) : void 0
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
var NeuroVersePlugin = class {
|
|
32
|
-
name = "neuroverse-governance";
|
|
33
|
-
world;
|
|
34
|
-
options;
|
|
35
|
-
engineOptions;
|
|
36
|
-
mapAction;
|
|
37
|
-
activePlan;
|
|
38
|
-
constructor(world, options = {}) {
|
|
39
|
-
this.world = world;
|
|
40
|
-
this.options = options;
|
|
41
|
-
this.activePlan = options.plan;
|
|
42
|
-
this.engineOptions = buildEngineOptions(options, this.activePlan);
|
|
43
|
-
this.mapAction = options.mapAction ?? defaultMapAction;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Evaluate an action before execution.
|
|
47
|
-
*
|
|
48
|
-
* @throws GovernanceBlockedError if BLOCKED
|
|
49
|
-
* @returns HookResult with verdict details
|
|
50
|
-
*/
|
|
51
|
-
beforeAction(action) {
|
|
52
|
-
const event = this.mapAction(action, "input");
|
|
53
|
-
this.engineOptions.plan = this.activePlan;
|
|
54
|
-
const verdict = evaluateGuard(event, this.world, this.engineOptions);
|
|
55
|
-
const result = {
|
|
56
|
-
allowed: verdict.status === "ALLOW",
|
|
57
|
-
verdict,
|
|
58
|
-
action
|
|
59
|
-
};
|
|
60
|
-
this.options.onEvaluate?.(result);
|
|
61
|
-
if (verdict.status === "BLOCK") {
|
|
62
|
-
throw new GovernanceBlockedError2(verdict, action);
|
|
63
|
-
}
|
|
64
|
-
if (verdict.status === "ALLOW") {
|
|
65
|
-
trackPlanProgress(event, this, this.options);
|
|
66
|
-
}
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Evaluate an action's output (post-execution governance).
|
|
71
|
-
* Only runs if evaluateOutputs is enabled.
|
|
72
|
-
*
|
|
73
|
-
* @returns HookResult or null if output evaluation is disabled
|
|
74
|
-
*/
|
|
75
|
-
afterAction(action, _output) {
|
|
76
|
-
if (!this.options.evaluateOutputs) return null;
|
|
77
|
-
const event = this.mapAction(action, "output");
|
|
78
|
-
const verdict = evaluateGuard(event, this.world, this.engineOptions);
|
|
79
|
-
const result = {
|
|
80
|
-
allowed: verdict.status === "ALLOW",
|
|
81
|
-
verdict,
|
|
82
|
-
action
|
|
83
|
-
};
|
|
84
|
-
this.options.onEvaluate?.(result);
|
|
85
|
-
if (verdict.status === "BLOCK") {
|
|
86
|
-
throw new GovernanceBlockedError2(verdict, action);
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Get the plugin hooks object for agent.use().
|
|
92
|
-
*/
|
|
93
|
-
hooks() {
|
|
94
|
-
return {
|
|
95
|
-
beforeAction: (action) => this.beforeAction(action),
|
|
96
|
-
afterAction: (action, output) => this.afterAction(action, output)
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
async function createNeuroVersePlugin(worldPath, options) {
|
|
101
|
-
const world = await loadWorld(worldPath);
|
|
102
|
-
return new NeuroVersePlugin(world, options);
|
|
103
|
-
}
|
|
104
|
-
function createNeuroVersePluginFromWorld(world, options) {
|
|
105
|
-
return new NeuroVersePlugin(world, options);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export {
|
|
109
|
-
GovernanceBlockedError2 as GovernanceBlockedError,
|
|
110
|
-
NeuroVersePlugin,
|
|
111
|
-
createNeuroVersePlugin,
|
|
112
|
-
createNeuroVersePluginFromWorld
|
|
113
|
-
};
|
package/dist/chunk-6CZSKEY5.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
// src/engine/plan-parser.ts
|
|
2
|
-
function slugify(text) {
|
|
3
|
-
return text.toLowerCase().replace(/[^a-z0-9\s]/g, "").trim().replace(/\s+/g, "_");
|
|
4
|
-
}
|
|
5
|
-
function extractBracketAnnotation(line, key) {
|
|
6
|
-
const regex = new RegExp(`\\[${key}:\\s*([^\\]]+)\\]`, "i");
|
|
7
|
-
const match = line.match(regex);
|
|
8
|
-
if (!match) return null;
|
|
9
|
-
return match[1].split(",").map((s) => s.trim()).filter(Boolean);
|
|
10
|
-
}
|
|
11
|
-
function extractParenAnnotation(line, key) {
|
|
12
|
-
const regex = new RegExp(`\\(${key}:\\s*([^)]+)\\)`, "i");
|
|
13
|
-
const match = line.match(regex);
|
|
14
|
-
if (!match) return null;
|
|
15
|
-
return match[1].split(",").map((s) => s.trim()).filter(Boolean);
|
|
16
|
-
}
|
|
17
|
-
function stripAnnotations(line) {
|
|
18
|
-
return line.replace(/\[(?:tools|tag|verify|type):\s*[^\]]+\]/gi, "").replace(/\((?:after):\s*[^)]+\)/gi, "").trim();
|
|
19
|
-
}
|
|
20
|
-
function parseFrontmatter(content) {
|
|
21
|
-
const frontmatter = {};
|
|
22
|
-
const fmMatch = content.match(/^---\s*\n([\s\S]*?)\n---\s*\n/);
|
|
23
|
-
if (!fmMatch) {
|
|
24
|
-
return { frontmatter, body: content };
|
|
25
|
-
}
|
|
26
|
-
const fmBody = fmMatch[1];
|
|
27
|
-
for (const line of fmBody.split("\n")) {
|
|
28
|
-
const colonIndex = line.indexOf(":");
|
|
29
|
-
if (colonIndex > 0) {
|
|
30
|
-
const key = line.slice(0, colonIndex).trim();
|
|
31
|
-
const value = line.slice(colonIndex + 1).trim();
|
|
32
|
-
frontmatter[key] = value;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return { frontmatter, body: content.slice(fmMatch[0].length) };
|
|
36
|
-
}
|
|
37
|
-
function parseSections(body) {
|
|
38
|
-
const steps = [];
|
|
39
|
-
const constraints = [];
|
|
40
|
-
let currentSection = "none";
|
|
41
|
-
for (const line of body.split("\n")) {
|
|
42
|
-
const trimmed = line.trim();
|
|
43
|
-
if (/^#+\s*Steps/i.test(trimmed)) {
|
|
44
|
-
currentSection = "steps";
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (/^#+\s*Constraints/i.test(trimmed)) {
|
|
48
|
-
currentSection = "constraints";
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (/^#+\s/.test(trimmed) && currentSection !== "none") {
|
|
52
|
-
currentSection = "none";
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (trimmed.startsWith("- ")) {
|
|
56
|
-
const item = trimmed.slice(2).trim();
|
|
57
|
-
if (currentSection === "steps") {
|
|
58
|
-
steps.push(item);
|
|
59
|
-
} else if (currentSection === "constraints") {
|
|
60
|
-
constraints.push(item);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return { steps, constraints };
|
|
65
|
-
}
|
|
66
|
-
function parseStep(raw) {
|
|
67
|
-
const label = stripAnnotations(raw);
|
|
68
|
-
const id = slugify(label);
|
|
69
|
-
const tools = extractBracketAnnotation(raw, "tools");
|
|
70
|
-
const tags = extractBracketAnnotation(raw, "tag");
|
|
71
|
-
const verifyArr = extractBracketAnnotation(raw, "verify");
|
|
72
|
-
const requires = extractParenAnnotation(raw, "after");
|
|
73
|
-
return {
|
|
74
|
-
id,
|
|
75
|
-
label,
|
|
76
|
-
tools: tools ?? void 0,
|
|
77
|
-
tags: tags ?? void 0,
|
|
78
|
-
verify: verifyArr?.[0] ?? void 0,
|
|
79
|
-
requires: requires ?? void 0,
|
|
80
|
-
status: "pending"
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function parseConstraint(raw, index) {
|
|
84
|
-
const typeAnnotation = extractBracketAnnotation(raw, "type");
|
|
85
|
-
const description = stripAnnotations(raw);
|
|
86
|
-
const id = `constraint_${index}`;
|
|
87
|
-
let type = "custom";
|
|
88
|
-
let enforcement = "block";
|
|
89
|
-
let limit;
|
|
90
|
-
let unit;
|
|
91
|
-
if (typeAnnotation?.[0] === "approval") {
|
|
92
|
-
type = "approval";
|
|
93
|
-
enforcement = "pause";
|
|
94
|
-
} else if (/budget|\$|spending|cost/i.test(description)) {
|
|
95
|
-
type = "budget";
|
|
96
|
-
const amountMatch = description.match(/\$?([\d,]+)/);
|
|
97
|
-
if (amountMatch) {
|
|
98
|
-
limit = parseInt(amountMatch[1].replace(/,/g, ""), 10);
|
|
99
|
-
unit = "USD";
|
|
100
|
-
}
|
|
101
|
-
} else if (/time|hour|minute|day|deadline/i.test(description)) {
|
|
102
|
-
type = "time";
|
|
103
|
-
} else if (/scope|access|database|production/i.test(description)) {
|
|
104
|
-
type = "scope";
|
|
105
|
-
}
|
|
106
|
-
const trigger = description.toLowerCase();
|
|
107
|
-
return {
|
|
108
|
-
id,
|
|
109
|
-
type,
|
|
110
|
-
description,
|
|
111
|
-
enforcement,
|
|
112
|
-
limit,
|
|
113
|
-
unit,
|
|
114
|
-
trigger
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
function parsePlanMarkdown(markdown) {
|
|
118
|
-
const errors = [];
|
|
119
|
-
const { frontmatter, body } = parseFrontmatter(markdown.trim());
|
|
120
|
-
const { steps: stepLines, constraints: constraintLines } = parseSections(body);
|
|
121
|
-
if (!frontmatter.plan_id) {
|
|
122
|
-
errors.push("Missing required field: plan_id");
|
|
123
|
-
}
|
|
124
|
-
if (stepLines.length === 0) {
|
|
125
|
-
errors.push("Plan must have at least one step");
|
|
126
|
-
}
|
|
127
|
-
if (errors.length > 0) {
|
|
128
|
-
return { success: false, errors };
|
|
129
|
-
}
|
|
130
|
-
const steps = stepLines.map((line) => parseStep(line));
|
|
131
|
-
const constraints = constraintLines.map((line, i) => parseConstraint(line, i));
|
|
132
|
-
let expires_at;
|
|
133
|
-
if (frontmatter.expires) {
|
|
134
|
-
expires_at = new Date(frontmatter.expires).toISOString();
|
|
135
|
-
}
|
|
136
|
-
const completionRaw = frontmatter.completion?.toLowerCase();
|
|
137
|
-
const completion = completionRaw === "verified" ? "verified" : "trust";
|
|
138
|
-
const plan = {
|
|
139
|
-
plan_id: frontmatter.plan_id,
|
|
140
|
-
objective: frontmatter.objective ?? "",
|
|
141
|
-
sequential: frontmatter.sequential === "true",
|
|
142
|
-
completion,
|
|
143
|
-
steps,
|
|
144
|
-
constraints,
|
|
145
|
-
world_id: frontmatter.world ?? void 0,
|
|
146
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
147
|
-
expires_at
|
|
148
|
-
};
|
|
149
|
-
return { success: true, plan, errors: [] };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// src/contracts/plan-contract.ts
|
|
153
|
-
var PLAN_EXIT_CODES = {
|
|
154
|
-
ON_PLAN: 0,
|
|
155
|
-
OFF_PLAN: 1,
|
|
156
|
-
CONSTRAINT_VIOLATED: 2,
|
|
157
|
-
ERROR: 3,
|
|
158
|
-
PLAN_COMPLETE: 4
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
export {
|
|
162
|
-
parsePlanMarkdown,
|
|
163
|
-
PLAN_EXIT_CODES
|
|
164
|
-
};
|