@unson/brainbase-mcp 0.3.1 → 0.4.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.
@@ -0,0 +1,32 @@
1
+ {
2
+ "contract": "judgment-dag-core",
3
+ "algorithm": "sha256",
4
+ "canonicalization": "UTF-8 lines sorted by path as path + NUL + sha256 + LF",
5
+ "files": [
6
+ {
7
+ "path": "contracts/judgment-dag/fixture.json",
8
+ "sha256": "c191ea129c55c97d131998698a79f656c900150fb97abb4715aa44d2abca39c5"
9
+ },
10
+ {
11
+ "path": "contracts/judgment-dag/schema.json",
12
+ "sha256": "af783617e76dc3cdc878210311821f9b0e982b31102ab6bf46ad726d5423745d"
13
+ },
14
+ {
15
+ "path": "contracts/judgment-dag/source-lock.json",
16
+ "sha256": "c7b3020fe3952d90bd8ed991f613be66c0798983bb6cc2285a9aefff7ab2f0e9"
17
+ },
18
+ {
19
+ "path": "docs/architecture/judgment-dag-core.md",
20
+ "sha256": "24305aaa97df9c734d468c49f52784e94b77a4f506bae41d482bee05625d7e2a"
21
+ },
22
+ {
23
+ "path": "docs/management/judgment-dag-milestones.md",
24
+ "sha256": "ef51313f33de64f702fd6c86012984bd70cf99eeca5b4f4cfc27f6cb266172bd"
25
+ },
26
+ {
27
+ "path": "README.md",
28
+ "sha256": "a263114611c100feb75f9d35ad793593eafb7dea217d846a99efacc06c7efa24"
29
+ }
30
+ ],
31
+ "digest": "e97cefb8dadd451d5929c266376f3774fa84dcdde412e5ff3305b9b70d580ecd"
32
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "j0-valid",
3
+ "version": "2026-08-20.1",
4
+ "nodes": [
5
+ { "id": "context.customer", "node_type": "observation", "layer": "context", "scope": { "type": "project", "id": "project-j0-fixture" }, "version": "1.0.0", "description": "customer observation", "depends_on": [], "input_contract": "fixture.input.v1", "output_contract": "fixture.output.v1", "runner_type": "deterministic", "authority": ["fixture-owner"], "confidence": 1, "valid_from": "2026-08-20T00:00:00.000Z", "valid_to": null, "provenance": [{ "source": "j0-fixture", "reference": "context.customer" }], "evaluation": { "criteria": ["context.customer is evaluated"] } },
6
+ { "id": "context.account", "node_type": "observation", "layer": "context", "scope": { "type": "project", "id": "project-j0-fixture" }, "version": "1.0.0", "description": "account observation", "depends_on": [], "input_contract": "fixture.input.v1", "output_contract": "fixture.output.v1", "runner_type": "deterministic", "authority": ["fixture-owner"], "confidence": 1, "valid_from": "2026-08-20T00:00:00.000Z", "valid_to": null, "provenance": [{ "source": "j0-fixture", "reference": "context.account" }], "evaluation": { "criteria": ["context.account is evaluated"] } },
7
+ { "id": "judgment.fit", "node_type": "judgment", "layer": "judgment", "scope": { "type": "project", "id": "project-j0-fixture" }, "version": "1.0.0", "description": "fit judgment", "depends_on": ["context.customer", "context.account"], "input_contract": "fixture.input.v1", "output_contract": "fixture.output.v1", "runner_type": "deterministic", "authority": ["fixture-owner"], "confidence": 1, "valid_from": "2026-08-20T00:00:00.000Z", "valid_to": null, "provenance": [{ "source": "j0-fixture", "reference": "judgment.fit" }], "evaluation": { "criteria": ["judgment.fit is evaluated"] } },
8
+ { "id": "resource.scope", "node_type": "resource", "layer": "resource", "scope": { "type": "project", "id": "project-j0-fixture" }, "version": "1.0.0", "description": "resource scope", "depends_on": ["judgment.fit"], "input_contract": "fixture.input.v1", "output_contract": "fixture.output.v1", "runner_type": "deterministic", "authority": ["fixture-owner"], "confidence": 1, "valid_from": "2026-08-20T00:00:00.000Z", "valid_to": null, "provenance": [{ "source": "j0-fixture", "reference": "resource.scope" }], "evaluation": { "criteria": ["resource.scope is evaluated"] } },
9
+ { "id": "execution.proposal", "node_type": "execution", "layer": "execution", "scope": { "type": "project", "id": "project-j0-fixture" }, "version": "1.0.0", "description": "execution proposal", "depends_on": ["resource.scope"], "input_contract": "fixture.input.v1", "output_contract": "fixture.output.v1", "runner_type": "deterministic", "authority": ["fixture-owner"], "confidence": 1, "valid_from": "2026-08-20T00:00:00.000Z", "valid_to": null, "provenance": [{ "source": "j0-fixture", "reference": "execution.proposal" }], "evaluation": { "criteria": ["execution.proposal is evaluated"] } },
10
+ { "id": "execution.outcome", "node_type": "outcome", "layer": "execution", "scope": { "type": "project", "id": "project-j0-fixture" }, "version": "1.0.0", "description": "execution outcome", "depends_on": ["execution.proposal"], "input_contract": "fixture.input.v1", "output_contract": "fixture.output.v1", "runner_type": "deterministic", "authority": ["fixture-owner"], "confidence": 1, "valid_from": "2026-08-20T00:00:00.000Z", "valid_to": null, "provenance": [{ "source": "j0-fixture", "reference": "execution.outcome" }], "evaluation": { "criteria": ["execution.outcome is evaluated"] } },
11
+ { "id": "evaluation.result", "node_type": "evaluation", "layer": "evaluation", "scope": { "type": "project", "id": "project-j0-fixture" }, "version": "1.0.0", "description": "evaluation result", "depends_on": ["execution.outcome"], "input_contract": "fixture.input.v1", "output_contract": "fixture.output.v1", "runner_type": "deterministic", "authority": ["fixture-owner"], "confidence": 1, "valid_from": "2026-08-20T00:00:00.000Z", "valid_to": null, "provenance": [{ "source": "j0-fixture", "reference": "evaluation.result" }], "evaluation": { "criteria": ["evaluation.result is evaluated"] } }
12
+ ],
13
+ "edges": [
14
+ { "from": "context.customer", "to": "judgment.fit", "relation": "depends_on" },
15
+ { "from": "context.account", "to": "judgment.fit", "relation": "depends_on" },
16
+ { "from": "judgment.fit", "to": "resource.scope", "relation": "depends_on" },
17
+ { "from": "resource.scope", "to": "execution.proposal", "relation": "depends_on" },
18
+ { "from": "execution.proposal", "to": "execution.outcome", "relation": "depends_on" },
19
+ { "from": "execution.outcome", "to": "evaluation.result", "relation": "depends_on" }
20
+ ]
21
+ }
@@ -0,0 +1,80 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/Unson-LLC/brainbase/blob/develop/contracts/judgment-dag/schema.json",
4
+ "title": "Brainbase Judgment DAG core contract",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["id", "version", "nodes", "edges"],
8
+ "properties": {
9
+ "id": { "$ref": "#/$defs/identifier" },
10
+ "version": { "type": "string", "minLength": 1, "pattern": "\\S" },
11
+ "nodes": { "type": "array", "items": { "$ref": "#/$defs/node" } },
12
+ "edges": { "type": "array", "items": { "$ref": "#/$defs/edge" } }
13
+ },
14
+ "$defs": {
15
+ "identifier": {
16
+ "type": "string",
17
+ "minLength": 1,
18
+ "pattern": "^(?![\\s\\S]*[\\u0000-\\u001F\\u007F])(?=[\\s\\S]*\\S)[\\s\\S]+$"
19
+ },
20
+ "metadata": {
21
+ "anyOf": [
22
+ { "type": "string" },
23
+ { "type": "number" },
24
+ { "type": "boolean" },
25
+ { "type": "null" },
26
+ { "type": "array", "items": { "$ref": "#/$defs/metadata" } },
27
+ { "type": "object", "additionalProperties": { "$ref": "#/$defs/metadata" } }
28
+ ]
29
+ },
30
+ "scope": {
31
+ "type": "object",
32
+ "additionalProperties": false,
33
+ "required": ["type", "id"],
34
+ "properties": {
35
+ "type": { "enum": ["personal", "project", "organization"] },
36
+ "id": { "$ref": "#/$defs/identifier" }
37
+ }
38
+ },
39
+ "node": {
40
+ "type": "object",
41
+ "additionalProperties": false,
42
+ "required": ["id", "node_type", "layer", "scope", "version", "description", "depends_on", "input_contract", "output_contract", "runner_type"],
43
+ "properties": {
44
+ "id": { "$ref": "#/$defs/identifier" },
45
+ "node_type": { "enum": ["observation", "judgment", "decision", "resource", "execution", "outcome", "evaluation"] },
46
+ "layer": { "enum": ["context", "judgment", "resource", "execution", "evaluation"] },
47
+ "scope": { "$ref": "#/$defs/scope" },
48
+ "version": { "type": "string", "minLength": 1, "pattern": "\\S" },
49
+ "description": { "type": "string", "minLength": 1, "pattern": "\\S" },
50
+ "depends_on": { "type": "array", "items": { "$ref": "#/$defs/identifier" }, "uniqueItems": true },
51
+ "input_contract": { "type": "string", "minLength": 1, "pattern": "\\S" },
52
+ "output_contract": { "type": "string", "minLength": 1, "pattern": "\\S" },
53
+ "runner_type": { "enum": ["deterministic", "agent", "human", "committee", "external"] },
54
+ "authority": { "$ref": "#/$defs/metadata" },
55
+ "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
56
+ "valid_from": { "type": ["string", "null"] },
57
+ "valid_to": { "type": ["string", "null"] },
58
+ "provenance": { "type": "array", "items": { "$ref": "#/$defs/metadata" } },
59
+ "evaluation": { "$ref": "#/$defs/metadata" }
60
+ },
61
+ "allOf": [
62
+ { "if": { "properties": { "node_type": { "const": "observation" } } }, "then": { "properties": { "layer": { "const": "context" } } } },
63
+ { "if": { "properties": { "node_type": { "enum": ["judgment", "decision"] } } }, "then": { "properties": { "layer": { "const": "judgment" } } } },
64
+ { "if": { "properties": { "node_type": { "const": "resource" } } }, "then": { "properties": { "layer": { "const": "resource" } } } },
65
+ { "if": { "properties": { "node_type": { "enum": ["execution", "outcome"] } } }, "then": { "properties": { "layer": { "const": "execution" } } } },
66
+ { "if": { "properties": { "node_type": { "const": "evaluation" } } }, "then": { "properties": { "layer": { "const": "evaluation" } } } }
67
+ ]
68
+ },
69
+ "edge": {
70
+ "type": "object",
71
+ "additionalProperties": false,
72
+ "required": ["from", "to", "relation"],
73
+ "properties": {
74
+ "from": { "$ref": "#/$defs/identifier" },
75
+ "to": { "$ref": "#/$defs/identifier" },
76
+ "relation": { "enum": ["depends_on", "supports", "contradicts", "gates", "supersedes", "produces", "evaluated_by", "triggers"] }
77
+ }
78
+ }
79
+ }
80
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "contract": "judgment-dag-core",
4
+ "repository": "https://github.com/Unson-LLC/brainbase",
5
+ "status": "accepted",
6
+ "accepted_base_commit": "7e5d5693f988f4ba84072c5910ef32f0e70871e1",
7
+ "sources": [
8
+ {
9
+ "kind": "architecture",
10
+ "path": "docs/architecture/judgment-dag-core.md",
11
+ "sha256": "24305aaa97df9c734d468c49f52784e94b77a4f506bae41d482bee05625d7e2a"
12
+ },
13
+ {
14
+ "kind": "milestones",
15
+ "path": "docs/management/judgment-dag-milestones.md",
16
+ "sha256": "ef51313f33de64f702fd6c86012984bd70cf99eeca5b4f4cfc27f6cb266172bd"
17
+ }
18
+ ],
19
+ "notes": [
20
+ "Outcome is produced and recorded by the Execution DAG and maps to the execution layer.",
21
+ "This J0 contract slice does not implement runner, artifact, execution-log, replay, evaluation, or mutation protection; those remain J0-2 non-goals and unverified.",
22
+ "Public DAG identifiers reject C0 and DEL control characters so dependency pair keys cannot collide.",
23
+ "J0 multi-tenancy evidence is limited to exact scope equality; cross-scope authorization, runtime, secret, database, and deployment are non-goals."
24
+ ]
25
+ }
@@ -0,0 +1,143 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://brainbase.pages.dev/contracts/public-message-candidate.schema.json",
4
+ "title": "Brainbase approved public-message candidate",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "schema_version",
9
+ "candidate_id",
10
+ "status",
11
+ "source",
12
+ "approval",
13
+ "copy"
14
+ ],
15
+ "properties": {
16
+ "schema_version": {
17
+ "const": "1.0.0"
18
+ },
19
+ "candidate_id": {
20
+ "type": "string",
21
+ "pattern": "^[a-z0-9][a-z0-9._-]{2,127}$"
22
+ },
23
+ "status": {
24
+ "const": "approved"
25
+ },
26
+ "source": {
27
+ "type": "object",
28
+ "additionalProperties": false,
29
+ "required": [
30
+ "type",
31
+ "entity_id",
32
+ "snapshot_hash",
33
+ "exported_at",
34
+ "scope"
35
+ ],
36
+ "properties": {
37
+ "type": {
38
+ "const": "brainbase_graph"
39
+ },
40
+ "entity_id": {
41
+ "type": "string",
42
+ "minLength": 1,
43
+ "maxLength": 200
44
+ },
45
+ "entity_version": {
46
+ "type": "integer",
47
+ "minimum": 1
48
+ },
49
+ "snapshot_hash": {
50
+ "type": "string",
51
+ "pattern": "^sha256:[0-9a-f]{64}$"
52
+ },
53
+ "exported_at": {
54
+ "type": "string",
55
+ "format": "date-time"
56
+ },
57
+ "scope": {
58
+ "type": "string",
59
+ "minLength": 1,
60
+ "maxLength": 100
61
+ }
62
+ }
63
+ },
64
+ "approval": {
65
+ "type": "object",
66
+ "additionalProperties": false,
67
+ "required": [
68
+ "status",
69
+ "approved_by",
70
+ "approved_at",
71
+ "reason"
72
+ ],
73
+ "properties": {
74
+ "status": {
75
+ "const": "approved"
76
+ },
77
+ "approved_by": {
78
+ "type": "string",
79
+ "minLength": 1,
80
+ "maxLength": 100
81
+ },
82
+ "approved_at": {
83
+ "type": "string",
84
+ "format": "date-time"
85
+ },
86
+ "reason": {
87
+ "type": "string",
88
+ "minLength": 1,
89
+ "maxLength": 1000
90
+ }
91
+ }
92
+ },
93
+ "copy": {
94
+ "$ref": "#/$defs/copy"
95
+ }
96
+ },
97
+ "$defs": {
98
+ "copy": {
99
+ "type": "object",
100
+ "additionalProperties": false,
101
+ "required": [
102
+ "headline",
103
+ "short_definition",
104
+ "definition",
105
+ "human_role",
106
+ "ai_role",
107
+ "package_description"
108
+ ],
109
+ "properties": {
110
+ "headline": {
111
+ "type": "string",
112
+ "minLength": 1,
113
+ "maxLength": 80
114
+ },
115
+ "short_definition": {
116
+ "type": "string",
117
+ "minLength": 1,
118
+ "maxLength": 160
119
+ },
120
+ "definition": {
121
+ "type": "string",
122
+ "minLength": 1,
123
+ "maxLength": 400
124
+ },
125
+ "human_role": {
126
+ "type": "string",
127
+ "minLength": 1,
128
+ "maxLength": 200
129
+ },
130
+ "ai_role": {
131
+ "type": "string",
132
+ "minLength": 1,
133
+ "maxLength": 240
134
+ },
135
+ "package_description": {
136
+ "type": "string",
137
+ "minLength": 1,
138
+ "maxLength": 240
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
package/dist/cli.js CHANGED
@@ -65,7 +65,7 @@ export async function runCli(argv = process.argv.slice(2), io = process) {
65
65
  case 'ontology:migrate':
66
66
  return await ontologyMigrate(parsed, io);
67
67
  case 'judgment:hook':
68
- return await judgmentHook(io);
68
+ return await judgmentHook(parsed, io);
69
69
  case 'judgment:install':
70
70
  return await judgmentInstall(parsed, io);
71
71
  case 'doctor':
@@ -83,12 +83,25 @@ export async function runCli(argv = process.argv.slice(2), io = process) {
83
83
  return 1;
84
84
  }
85
85
  }
86
- async function judgmentHook(io) {
86
+ function judgmentAutonomyOptions(parsed) {
87
+ const rawMode = first(parsed, 'autonomy-mode');
88
+ if (rawMode !== undefined && !['off', 'canary', 'on'].includes(rawMode)) {
89
+ throw new Error('judgment_autonomy_mode_invalid');
90
+ }
91
+ const project = first(parsed, 'autonomy-project')?.trim();
92
+ if (rawMode === 'canary' && !project)
93
+ throw new Error('judgment_autonomy_canary_project_missing');
94
+ return {
95
+ ...(rawMode ? { autonomyMode: rawMode } : {}),
96
+ ...(project ? { autonomyCanaryProjects: [project] } : {})
97
+ };
98
+ }
99
+ async function judgmentHook(parsed, io) {
87
100
  let payload = {};
88
101
  try {
89
102
  const input = await readHookStdin(io.stdin ?? process.stdin);
90
103
  payload = JSON.parse(input || '{}');
91
- write(io, `${JSON.stringify(await processJudgmentHook(payload))}\n`);
104
+ write(io, `${JSON.stringify(await processJudgmentHook(payload, judgmentAutonomyOptions(parsed)))}\n`);
92
105
  }
93
106
  catch (error) {
94
107
  const reason = error instanceof Error ? error.message : String(error);
@@ -106,10 +119,20 @@ async function judgmentInstall(parsed, io) {
106
119
  if (target !== 'codex')
107
120
  throw new Error('judgment:install currently requires --target codex');
108
121
  const cliPath = fileURLToPath(new URL('./cli.js', import.meta.url));
122
+ const autonomy = judgmentAutonomyOptions(parsed);
123
+ const hookArguments = [
124
+ process.execPath,
125
+ cliPath,
126
+ 'judgment:hook',
127
+ ...(autonomy.autonomyMode ? ['--autonomy-mode', autonomy.autonomyMode] : []),
128
+ ...(autonomy.autonomyCanaryProjects?.[0]
129
+ ? ['--autonomy-project', autonomy.autonomyCanaryProjects[0]]
130
+ : [])
131
+ ];
109
132
  const hook = {
110
133
  hooks: [{
111
134
  type: 'command',
112
- command: `${JSON.stringify(process.execPath)} ${JSON.stringify(cliPath)} judgment:hook`,
135
+ command: hookArguments.map((argument) => JSON.stringify(argument)).join(' '),
113
136
  statusMessage: 'brainbase judgment resolver'
114
137
  }]
115
138
  };
@@ -1065,8 +1088,8 @@ function usage() {
1065
1088
  brainbase ontology:show
1066
1089
  brainbase ontology:audit [--dir path] [--ontology-version 0.0.0|1.0.0|2.0.0]
1067
1090
  brainbase ontology:migrate [--dir path] [--write --expected-input-digest digest]
1068
- brainbase judgment:install --target codex [--dry-run] [--output path]
1069
- brainbase judgment:hook
1091
+ brainbase judgment:install --target codex [--autonomy-mode off|canary|on] [--autonomy-project code] [--dry-run] [--output path]
1092
+ brainbase judgment:hook [--autonomy-mode off|canary|on] [--autonomy-project code]
1070
1093
  brainbase doctor [--dir path] [--judgment-hooks path]
1071
1094
  `;
1072
1095
  }
@@ -0,0 +1,62 @@
1
+ export type JudgmentAutonomyVerdict = 'continue' | 'human_required' | 'not_applicable';
2
+ export type JudgmentAutonomyReasonCode = 'not_a_human_escalation' | 'routine_reversible_work' | 'semantic_judgment_required' | 'irreversible_external_action' | 'missing_authority_or_secret' | 'material_commitment' | 'owner_value_choice' | 'resolver_selected_clarification' | 'resolver_continue' | 'resolver_human_required';
3
+ export interface JudgmentAutonomyInstructionPatch {
4
+ cancel: readonly string[];
5
+ do_next: readonly string[];
6
+ acceptance_criteria: readonly string[];
7
+ }
8
+ export interface JudgmentAutonomyContext {
9
+ turn_id: string;
10
+ request: string;
11
+ final_answer: string;
12
+ project_code?: string;
13
+ selected_dag_ids: readonly string[];
14
+ }
15
+ export interface JudgmentAutonomyResolverRequest {
16
+ schema_version: 'brainbase-autonomy-resolver-request-v1';
17
+ case_id: string;
18
+ turn_id: string;
19
+ task_request: string;
20
+ proposed_human_question: string;
21
+ project_code?: string;
22
+ selected_dag_ids: readonly string[];
23
+ policy: {
24
+ default_behavior: 'continue';
25
+ complexity_behavior: 'decompose_and_continue';
26
+ human_only: readonly [
27
+ 'irreversible_external_action',
28
+ 'missing_authority_or_secret',
29
+ 'material_commitment',
30
+ 'new_owner_value_choice'
31
+ ];
32
+ };
33
+ }
34
+ export interface JudgmentAutonomyResolverDecision {
35
+ schema_version: 'brainbase-autonomy-resolver-decision-v1';
36
+ case_id: string;
37
+ verdict: 'continue' | 'human_required';
38
+ reason_code: string;
39
+ reason: string;
40
+ basis: ReadonlyArray<{
41
+ entity_id: string;
42
+ application: string;
43
+ }>;
44
+ instruction_patch?: JudgmentAutonomyInstructionPatch;
45
+ human_question?: string;
46
+ }
47
+ export type JudgmentAutonomyResolver = (request: JudgmentAutonomyResolverRequest) => Promise<JudgmentAutonomyResolverDecision>;
48
+ export interface JudgmentAutonomyEvaluation {
49
+ schema_version: 'brainbase-autonomy-evaluation-v1';
50
+ case_id: string;
51
+ verdict: JudgmentAutonomyVerdict;
52
+ reason_code: JudgmentAutonomyReasonCode;
53
+ reason: string;
54
+ question: string | null;
55
+ source: 'deterministic' | 'same_codex' | 'independent_resolver';
56
+ instruction_patch: JudgmentAutonomyInstructionPatch | null;
57
+ resolver_decision: JudgmentAutonomyResolverDecision | null;
58
+ }
59
+ export declare function visibleAnswerBody(answer: string): string;
60
+ export declare function extractHumanDecisionQuestion(answer: string): string | null;
61
+ export declare function evaluateJudgmentAutonomy(context: JudgmentAutonomyContext, resolver?: JudgmentAutonomyResolver): Promise<JudgmentAutonomyEvaluation>;
62
+ export declare function renderJudgmentAutonomyContinuation(evaluation: JudgmentAutonomyEvaluation): string;