@unson/brainbase-mcp 0.4.0 → 0.5.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/README.md +146 -471
- package/contracts/judgment-dag/digest.json +4 -4
- package/contracts/judgment-dag/source-lock.json +65 -1
- package/contracts/judgment-value-proof/fixture.json +54 -0
- package/contracts/judgment-value-proof/schema.json +163 -0
- package/contracts/public-message-candidate.schema.json +143 -0
- package/dist/cli.js +46 -6
- package/dist/embedding-provider.d.ts +72 -0
- package/dist/embedding-provider.js +391 -0
- package/dist/graph-retrieval.d.ts +94 -0
- package/dist/graph-retrieval.js +443 -0
- package/dist/judgment-autonomy.d.ts +62 -0
- package/dist/judgment-autonomy.js +301 -0
- package/dist/judgment-dag-artifact-store.d.ts +29 -0
- package/dist/judgment-dag-artifact-store.js +416 -0
- package/dist/judgment-dag-replay-evaluation.d.ts +108 -0
- package/dist/judgment-dag-replay-evaluation.js +424 -0
- package/dist/judgment-dag-runner.d.ts +70 -0
- package/dist/judgment-dag-runner.js +325 -0
- package/dist/judgment-dag.d.ts +6 -0
- package/dist/judgment-dag.js +3 -0
- package/dist/judgment-host.d.ts +21 -0
- package/dist/judgment-host.js +180 -0
- package/dist/judgment-value-proof.d.ts +92 -0
- package/dist/judgment-value-proof.js +229 -0
- package/dist/organization-graph.d.ts +76 -0
- package/dist/organization-graph.js +331 -0
- package/dist/portable-graph.d.ts +39 -0
- package/dist/portable-graph.js +240 -0
- package/dist/server.d.ts +42 -3
- package/dist/server.js +52 -7
- package/docs/management/judgment-dag-milestones.md +31 -1
- package/package.json +20 -4
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
"path": "contracts/judgment-dag/source-lock.json",
|
|
16
|
-
"sha256": "
|
|
16
|
+
"sha256": "4d3fbc2f82c07f709d901fcda68718b12b45a0d11a16354edec32b3406370bfe"
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
"path": "docs/architecture/judgment-dag-core.md",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
"path": "docs/management/judgment-dag-milestones.md",
|
|
24
|
-
"sha256": "
|
|
24
|
+
"sha256": "e028f084708aa4ef2dea9437b81d3c2de15cb62b2c9448f2c7fa7d9d32b1e6b2"
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
"path": "README.md",
|
|
28
|
-
"sha256": "
|
|
28
|
+
"sha256": "ec2f2419e7f43e2abdbedf6535e6d57a095e920f6c42b9e250bbabb50c00b745"
|
|
29
29
|
}
|
|
30
30
|
],
|
|
31
|
-
"digest": "
|
|
31
|
+
"digest": "dbe232857d29a3178013c82fc80d87dadecf0fa07ebf5ca5d260b0eed35c34fb"
|
|
32
32
|
}
|
|
@@ -4,6 +4,70 @@
|
|
|
4
4
|
"repository": "https://github.com/Unson-LLC/brainbase",
|
|
5
5
|
"status": "accepted",
|
|
6
6
|
"accepted_base_commit": "7e5d5693f988f4ba84072c5910ef32f0e70871e1",
|
|
7
|
+
"program_governance": {
|
|
8
|
+
"repository": "https://github.com/Unson-LLC/brainbase-unson",
|
|
9
|
+
"commit": "18544f58a2a0298d97eab45de2f05544bed48a43",
|
|
10
|
+
"markdown": {
|
|
11
|
+
"path": "docs/management/milestones/brainbase-program-master-roadmap.md",
|
|
12
|
+
"sha256": "167afb6d3fc57198c9f5ffca06fbafea968a5435af04f44b55017199b6d859fe"
|
|
13
|
+
},
|
|
14
|
+
"machine_contract": {
|
|
15
|
+
"path": "docs/management/milestones/brainbase-program-master-roadmap.json",
|
|
16
|
+
"sha256": "f3e6e023060ef3976f367ed7efa62ac57f7091f517ea1ca1d13824d9e6ca429f"
|
|
17
|
+
},
|
|
18
|
+
"work_packages": [
|
|
19
|
+
"R0",
|
|
20
|
+
"J0",
|
|
21
|
+
"G0",
|
|
22
|
+
"R1",
|
|
23
|
+
"D0",
|
|
24
|
+
"P0",
|
|
25
|
+
"C0"
|
|
26
|
+
],
|
|
27
|
+
"milestone_crosswalk": {
|
|
28
|
+
"M0": [
|
|
29
|
+
"R0",
|
|
30
|
+
"J0"
|
|
31
|
+
],
|
|
32
|
+
"M1": [
|
|
33
|
+
"J0"
|
|
34
|
+
],
|
|
35
|
+
"M2": [
|
|
36
|
+
"G0"
|
|
37
|
+
],
|
|
38
|
+
"M3": [
|
|
39
|
+
"R1"
|
|
40
|
+
],
|
|
41
|
+
"M4": [
|
|
42
|
+
"D0"
|
|
43
|
+
],
|
|
44
|
+
"M5": [
|
|
45
|
+
"P0"
|
|
46
|
+
],
|
|
47
|
+
"M6": [
|
|
48
|
+
"G0",
|
|
49
|
+
"C0"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"status_vocabulary": [
|
|
53
|
+
"planned",
|
|
54
|
+
"contract_ready",
|
|
55
|
+
"implementing",
|
|
56
|
+
"verified",
|
|
57
|
+
"production_proven",
|
|
58
|
+
"done"
|
|
59
|
+
],
|
|
60
|
+
"snapshot_update_policy": {
|
|
61
|
+
"requires_new_commit": true,
|
|
62
|
+
"required_artifact_hashes": [
|
|
63
|
+
"markdown.sha256",
|
|
64
|
+
"machine_contract.sha256"
|
|
65
|
+
],
|
|
66
|
+
"requires_verification_evidence": true,
|
|
67
|
+
"requires_independent_review": true
|
|
68
|
+
},
|
|
69
|
+
"verification_boundary": "The OSS package records the accepted cross-repository commit and content hashes. Public tests do not fetch the organization repository or treat network access as runtime authority."
|
|
70
|
+
},
|
|
7
71
|
"sources": [
|
|
8
72
|
{
|
|
9
73
|
"kind": "architecture",
|
|
@@ -13,7 +77,7 @@
|
|
|
13
77
|
{
|
|
14
78
|
"kind": "milestones",
|
|
15
79
|
"path": "docs/management/judgment-dag-milestones.md",
|
|
16
|
-
"sha256": "
|
|
80
|
+
"sha256": "e028f084708aa4ef2dea9437b81d3c2de15cb62b2c9448f2c7fa7d9d32b1e6b2"
|
|
17
81
|
}
|
|
18
82
|
],
|
|
19
83
|
"notes": [
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema_version": "brainbase-judgment-value-proof-v1",
|
|
3
|
+
"intent_id": "intent_example",
|
|
4
|
+
"decision_attempt_id": "decision_attempt_example",
|
|
5
|
+
"recorded_at": "2026-09-01T00:00:00.000Z",
|
|
6
|
+
"state": "outcome_verified",
|
|
7
|
+
"interruption": {
|
|
8
|
+
"resolution": "continued_without_human",
|
|
9
|
+
"question_display_text": "新規文書を作るか、既存文書を更新するか",
|
|
10
|
+
"question_digest": "sha256:example-question",
|
|
11
|
+
"reason_code": "routine_reversible_work",
|
|
12
|
+
"human_reason": null
|
|
13
|
+
},
|
|
14
|
+
"decision": {
|
|
15
|
+
"summary": "既存SSOTを最小更新する",
|
|
16
|
+
"work_impact": "確認で作業を止めず、実装と検証まで継続した",
|
|
17
|
+
"basis": [
|
|
18
|
+
{
|
|
19
|
+
"entity_id": "dec_example",
|
|
20
|
+
"application": "正本が存在する場合は重複する文書を増やさない"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"prior_learning_reused": true
|
|
24
|
+
},
|
|
25
|
+
"execution": {
|
|
26
|
+
"status": "completed",
|
|
27
|
+
"summary": "既存文書を更新してPRを作成した",
|
|
28
|
+
"artifact_refs": [
|
|
29
|
+
{
|
|
30
|
+
"kind": "pull_request",
|
|
31
|
+
"ref": "github://pull/142",
|
|
32
|
+
"label": "PR #142"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"outcome": {
|
|
37
|
+
"status": "outcome_verified",
|
|
38
|
+
"summary": "PRを読み戻し、変更内容とテスト成功を確認した",
|
|
39
|
+
"evidence_refs": [
|
|
40
|
+
{
|
|
41
|
+
"kind": "canonical_readback",
|
|
42
|
+
"ref": "github://pull/142",
|
|
43
|
+
"status": "verified",
|
|
44
|
+
"label": "PR #142"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
"human_decision": null,
|
|
49
|
+
"feedback": {
|
|
50
|
+
"status": "none",
|
|
51
|
+
"summary": null,
|
|
52
|
+
"evidence_ref": null
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://brainbase.local/contracts/judgment-value-proof/v1/schema.json",
|
|
4
|
+
"title": "Brainbase Judgment Value Proof v1",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"required": [
|
|
8
|
+
"schema_version",
|
|
9
|
+
"intent_id",
|
|
10
|
+
"decision_attempt_id",
|
|
11
|
+
"recorded_at",
|
|
12
|
+
"state",
|
|
13
|
+
"interruption",
|
|
14
|
+
"decision",
|
|
15
|
+
"execution",
|
|
16
|
+
"outcome",
|
|
17
|
+
"human_decision",
|
|
18
|
+
"feedback"
|
|
19
|
+
],
|
|
20
|
+
"properties": {
|
|
21
|
+
"schema_version": { "const": "brainbase-judgment-value-proof-v1" },
|
|
22
|
+
"intent_id": { "type": "string", "minLength": 1 },
|
|
23
|
+
"decision_attempt_id": { "type": "string", "minLength": 1 },
|
|
24
|
+
"recorded_at": { "type": "string", "format": "date-time" },
|
|
25
|
+
"state": {
|
|
26
|
+
"enum": ["captured", "executing", "waiting_human", "outcome_verified", "blocked", "unconfirmed"]
|
|
27
|
+
},
|
|
28
|
+
"interruption": {
|
|
29
|
+
"type": "object",
|
|
30
|
+
"additionalProperties": false,
|
|
31
|
+
"required": ["resolution", "question_display_text", "question_digest", "reason_code", "human_reason"],
|
|
32
|
+
"properties": {
|
|
33
|
+
"resolution": { "enum": ["not_applicable", "continued_without_human", "human_required"] },
|
|
34
|
+
"question_display_text": { "type": ["string", "null"] },
|
|
35
|
+
"question_digest": { "type": ["string", "null"] },
|
|
36
|
+
"reason_code": { "type": ["string", "null"] },
|
|
37
|
+
"human_reason": { "type": ["string", "null"] }
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"decision": {
|
|
41
|
+
"type": "object",
|
|
42
|
+
"additionalProperties": false,
|
|
43
|
+
"required": ["summary", "work_impact", "basis", "prior_learning_reused"],
|
|
44
|
+
"properties": {
|
|
45
|
+
"summary": { "type": ["string", "null"] },
|
|
46
|
+
"work_impact": { "type": ["string", "null"] },
|
|
47
|
+
"basis": {
|
|
48
|
+
"type": "array",
|
|
49
|
+
"items": { "$ref": "#/$defs/basis" }
|
|
50
|
+
},
|
|
51
|
+
"prior_learning_reused": {
|
|
52
|
+
"oneOf": [
|
|
53
|
+
{ "type": "boolean" },
|
|
54
|
+
{ "const": "unconfirmed" }
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"execution": {
|
|
60
|
+
"type": "object",
|
|
61
|
+
"additionalProperties": false,
|
|
62
|
+
"required": ["status", "summary", "artifact_refs"],
|
|
63
|
+
"properties": {
|
|
64
|
+
"status": { "enum": ["not_started", "executing", "completed", "blocked"] },
|
|
65
|
+
"summary": { "type": ["string", "null"] },
|
|
66
|
+
"artifact_refs": {
|
|
67
|
+
"type": "array",
|
|
68
|
+
"items": { "$ref": "#/$defs/artifact_ref" }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"outcome": {
|
|
73
|
+
"type": "object",
|
|
74
|
+
"additionalProperties": false,
|
|
75
|
+
"required": ["status", "summary", "evidence_refs"],
|
|
76
|
+
"properties": {
|
|
77
|
+
"status": { "enum": ["outcome_verified", "unconfirmed", "not_applicable"] },
|
|
78
|
+
"summary": { "type": ["string", "null"] },
|
|
79
|
+
"evidence_refs": {
|
|
80
|
+
"type": "array",
|
|
81
|
+
"items": { "$ref": "#/$defs/evidence_ref" }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"human_decision": {
|
|
86
|
+
"oneOf": [
|
|
87
|
+
{ "type": "null" },
|
|
88
|
+
{
|
|
89
|
+
"type": "object",
|
|
90
|
+
"additionalProperties": false,
|
|
91
|
+
"required": ["question", "why_human", "options"],
|
|
92
|
+
"properties": {
|
|
93
|
+
"question": { "type": "string", "minLength": 1 },
|
|
94
|
+
"why_human": { "type": "string", "minLength": 1 },
|
|
95
|
+
"options": {
|
|
96
|
+
"type": "array",
|
|
97
|
+
"items": { "$ref": "#/$defs/human_option" }
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
"feedback": {
|
|
104
|
+
"type": "object",
|
|
105
|
+
"additionalProperties": false,
|
|
106
|
+
"required": ["status", "summary", "evidence_ref"],
|
|
107
|
+
"properties": {
|
|
108
|
+
"status": { "enum": ["none", "pending", "accepted", "corrected", "next_time_ask", "reverted"] },
|
|
109
|
+
"summary": { "type": ["string", "null"] },
|
|
110
|
+
"evidence_ref": {
|
|
111
|
+
"oneOf": [
|
|
112
|
+
{ "type": "null" },
|
|
113
|
+
{ "$ref": "#/$defs/evidence_ref" }
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"$defs": {
|
|
120
|
+
"basis": {
|
|
121
|
+
"type": "object",
|
|
122
|
+
"additionalProperties": false,
|
|
123
|
+
"required": ["entity_id", "application"],
|
|
124
|
+
"properties": {
|
|
125
|
+
"entity_id": { "type": "string", "minLength": 1 },
|
|
126
|
+
"application": { "type": "string", "minLength": 1 }
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"artifact_ref": {
|
|
130
|
+
"type": "object",
|
|
131
|
+
"additionalProperties": false,
|
|
132
|
+
"required": ["kind", "ref"],
|
|
133
|
+
"properties": {
|
|
134
|
+
"kind": { "type": "string", "minLength": 1 },
|
|
135
|
+
"ref": { "type": "string", "minLength": 1 },
|
|
136
|
+
"label": { "type": "string", "minLength": 1 }
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"evidence_ref": {
|
|
140
|
+
"type": "object",
|
|
141
|
+
"additionalProperties": false,
|
|
142
|
+
"required": ["kind", "ref", "status"],
|
|
143
|
+
"properties": {
|
|
144
|
+
"kind": {
|
|
145
|
+
"enum": ["judgment_receipt", "autonomy_receipt", "tool_event", "artifact", "canonical_readback", "human_feedback"]
|
|
146
|
+
},
|
|
147
|
+
"ref": { "type": "string", "minLength": 1 },
|
|
148
|
+
"status": { "enum": ["verified", "unconfirmed"] },
|
|
149
|
+
"label": { "type": "string", "minLength": 1 }
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
"human_option": {
|
|
153
|
+
"type": "object",
|
|
154
|
+
"additionalProperties": false,
|
|
155
|
+
"required": ["id", "label", "impact"],
|
|
156
|
+
"properties": {
|
|
157
|
+
"id": { "type": "string", "minLength": 1 },
|
|
158
|
+
"label": { "type": "string", "minLength": 1 },
|
|
159
|
+
"impact": { "type": "string", "minLength": 1 }
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -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
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { createPortableGraph, portableGraphDigest } from './portable-graph.js';
|
|
3
|
+
import { createOrganizationGraphConfig, createOrganizationGraphClient } from './organization-graph.js';
|
|
2
4
|
import { constants, realpathSync } from 'node:fs';
|
|
3
5
|
import { access, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
6
|
import { delimiter, dirname, isAbsolute, join } from 'node:path';
|
|
@@ -25,6 +27,20 @@ export async function runCli(argv = process.argv.slice(2), io = process) {
|
|
|
25
27
|
return 0;
|
|
26
28
|
}
|
|
27
29
|
switch (parsed.command) {
|
|
30
|
+
case 'graph:upgrade': {
|
|
31
|
+
const config = createOrganizationGraphConfig();
|
|
32
|
+
if (!config)
|
|
33
|
+
throw new Error('graph:upgrade requires all BRAINBASE_ORGANIZATION_* settings');
|
|
34
|
+
const bundle = createPortableGraph(await loadPersonalOs(resolveDataDir(first(parsed, 'dir'))));
|
|
35
|
+
const client = createOrganizationGraphClient(config);
|
|
36
|
+
const imported = await client.importPortableGraph(bundle);
|
|
37
|
+
const readback = await client.readPortableGraph();
|
|
38
|
+
if (readback.digest !== portableGraphDigest(bundle))
|
|
39
|
+
throw new Error('organization_graph_readback_mismatch');
|
|
40
|
+
write(io, JSON.stringify({ status: imported.status, digest: readback.digest, readbackVerified: true,
|
|
41
|
+
sourceFilesUnchanged: true, graphId: config.graphId }) + '\n');
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
28
44
|
case 'onboard:init':
|
|
29
45
|
return await onboardInit(parsed, io);
|
|
30
46
|
case 'onboard:seed':
|
|
@@ -65,7 +81,7 @@ export async function runCli(argv = process.argv.slice(2), io = process) {
|
|
|
65
81
|
case 'ontology:migrate':
|
|
66
82
|
return await ontologyMigrate(parsed, io);
|
|
67
83
|
case 'judgment:hook':
|
|
68
|
-
return await judgmentHook(io);
|
|
84
|
+
return await judgmentHook(parsed, io);
|
|
69
85
|
case 'judgment:install':
|
|
70
86
|
return await judgmentInstall(parsed, io);
|
|
71
87
|
case 'doctor':
|
|
@@ -83,12 +99,25 @@ export async function runCli(argv = process.argv.slice(2), io = process) {
|
|
|
83
99
|
return 1;
|
|
84
100
|
}
|
|
85
101
|
}
|
|
86
|
-
|
|
102
|
+
function judgmentAutonomyOptions(parsed) {
|
|
103
|
+
const rawMode = first(parsed, 'autonomy-mode');
|
|
104
|
+
if (rawMode !== undefined && !['off', 'canary', 'on'].includes(rawMode)) {
|
|
105
|
+
throw new Error('judgment_autonomy_mode_invalid');
|
|
106
|
+
}
|
|
107
|
+
const project = first(parsed, 'autonomy-project')?.trim();
|
|
108
|
+
if (rawMode === 'canary' && !project)
|
|
109
|
+
throw new Error('judgment_autonomy_canary_project_missing');
|
|
110
|
+
return {
|
|
111
|
+
...(rawMode ? { autonomyMode: rawMode } : {}),
|
|
112
|
+
...(project ? { autonomyCanaryProjects: [project] } : {})
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async function judgmentHook(parsed, io) {
|
|
87
116
|
let payload = {};
|
|
88
117
|
try {
|
|
89
118
|
const input = await readHookStdin(io.stdin ?? process.stdin);
|
|
90
119
|
payload = JSON.parse(input || '{}');
|
|
91
|
-
write(io, `${JSON.stringify(await processJudgmentHook(payload))}\n`);
|
|
120
|
+
write(io, `${JSON.stringify(await processJudgmentHook(payload, judgmentAutonomyOptions(parsed)))}\n`);
|
|
92
121
|
}
|
|
93
122
|
catch (error) {
|
|
94
123
|
const reason = error instanceof Error ? error.message : String(error);
|
|
@@ -106,10 +135,20 @@ async function judgmentInstall(parsed, io) {
|
|
|
106
135
|
if (target !== 'codex')
|
|
107
136
|
throw new Error('judgment:install currently requires --target codex');
|
|
108
137
|
const cliPath = fileURLToPath(new URL('./cli.js', import.meta.url));
|
|
138
|
+
const autonomy = judgmentAutonomyOptions(parsed);
|
|
139
|
+
const hookArguments = [
|
|
140
|
+
process.execPath,
|
|
141
|
+
cliPath,
|
|
142
|
+
'judgment:hook',
|
|
143
|
+
...(autonomy.autonomyMode ? ['--autonomy-mode', autonomy.autonomyMode] : []),
|
|
144
|
+
...(autonomy.autonomyCanaryProjects?.[0]
|
|
145
|
+
? ['--autonomy-project', autonomy.autonomyCanaryProjects[0]]
|
|
146
|
+
: [])
|
|
147
|
+
];
|
|
109
148
|
const hook = {
|
|
110
149
|
hooks: [{
|
|
111
150
|
type: 'command',
|
|
112
|
-
command:
|
|
151
|
+
command: hookArguments.map((argument) => JSON.stringify(argument)).join(' '),
|
|
113
152
|
statusMessage: 'brainbase judgment resolver'
|
|
114
153
|
}]
|
|
115
154
|
};
|
|
@@ -1064,9 +1103,10 @@ function usage() {
|
|
|
1064
1103
|
brainbase onboard:skills --target codex|claude|portable [--skills id,id] [--out dir] [--format markdown|json]
|
|
1065
1104
|
brainbase ontology:show
|
|
1066
1105
|
brainbase ontology:audit [--dir path] [--ontology-version 0.0.0|1.0.0|2.0.0]
|
|
1106
|
+
brainbase graph:upgrade [--dir path]
|
|
1067
1107
|
brainbase ontology:migrate [--dir path] [--write --expected-input-digest digest]
|
|
1068
|
-
brainbase judgment:install --target codex [--dry-run] [--output path]
|
|
1069
|
-
brainbase judgment:hook
|
|
1108
|
+
brainbase judgment:install --target codex [--autonomy-mode off|canary|on] [--autonomy-project code] [--dry-run] [--output path]
|
|
1109
|
+
brainbase judgment:hook [--autonomy-mode off|canary|on] [--autonomy-project code]
|
|
1070
1110
|
brainbase doctor [--dir path] [--judgment-hooks path]
|
|
1071
1111
|
`;
|
|
1072
1112
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A provider is deliberately small so the retrieval layer does not need to
|
|
3
|
+
* know whether embeddings are produced by a local service or a hosted one.
|
|
4
|
+
* Brainbase does not bundle a model; the HTTP adapter below is opt-in.
|
|
5
|
+
*/
|
|
6
|
+
export interface EmbeddingProvider {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
embed(texts: string[]): Promise<number[][]>;
|
|
9
|
+
}
|
|
10
|
+
export type EmbeddingFetchResponse = {
|
|
11
|
+
readonly status: number;
|
|
12
|
+
readonly ok?: boolean;
|
|
13
|
+
readonly headers?: {
|
|
14
|
+
get(name: string): string | null;
|
|
15
|
+
} | Map<string, string> | Record<string, string | undefined>;
|
|
16
|
+
readonly body?: {
|
|
17
|
+
getReader(): {
|
|
18
|
+
read(): Promise<{
|
|
19
|
+
done: boolean;
|
|
20
|
+
value?: Uint8Array;
|
|
21
|
+
}>;
|
|
22
|
+
cancel?(reason?: unknown): Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
} | null;
|
|
25
|
+
text?(): Promise<string>;
|
|
26
|
+
json?(): Promise<unknown>;
|
|
27
|
+
};
|
|
28
|
+
export type EmbeddingFetch = (input: string, init: {
|
|
29
|
+
method: 'POST';
|
|
30
|
+
headers: Record<string, string>;
|
|
31
|
+
body: string;
|
|
32
|
+
redirect: 'error';
|
|
33
|
+
signal: AbortSignal;
|
|
34
|
+
}) => Promise<EmbeddingFetchResponse>;
|
|
35
|
+
export interface HttpEmbeddingProviderConfig {
|
|
36
|
+
/** Full OpenAI-compatible /embeddings endpoint. */
|
|
37
|
+
url: string;
|
|
38
|
+
model: string;
|
|
39
|
+
apiKey?: string;
|
|
40
|
+
/** Test injection point. The default is the host's global fetch. */
|
|
41
|
+
fetch?: EmbeddingFetch;
|
|
42
|
+
/** Alias accepted for callers that avoid shadowing the global fetch name. */
|
|
43
|
+
fetchImpl?: EmbeddingFetch;
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
cacheSize?: number;
|
|
46
|
+
}
|
|
47
|
+
export declare const EMBEDDING_MAX_INPUTS = 64;
|
|
48
|
+
/** Maximum number of texts accepted by one embed() call across all batches. */
|
|
49
|
+
export declare const EMBEDDING_MAX_TOTAL_INPUTS = 2048;
|
|
50
|
+
export declare const EMBEDDING_MAX_TEXT_LENGTH = 16000;
|
|
51
|
+
export declare const EMBEDDING_MAX_BATCH_BYTES = 1000000;
|
|
52
|
+
export declare const EMBEDDING_MAX_RESPONSE_BYTES = 4000000;
|
|
53
|
+
export declare const EMBEDDING_DEFAULT_TIMEOUT_MS = 10000;
|
|
54
|
+
export declare const EMBEDDING_DEFAULT_CACHE_SIZE = 2048;
|
|
55
|
+
export declare class EmbeddingProviderConfigError extends Error {
|
|
56
|
+
readonly code = "embedding_config_invalid";
|
|
57
|
+
constructor(message: string);
|
|
58
|
+
}
|
|
59
|
+
export declare class EmbeddingProviderError extends Error {
|
|
60
|
+
readonly code: string;
|
|
61
|
+
constructor(code: string, message: string);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Build an opt-in provider from environment variables.
|
|
65
|
+
*
|
|
66
|
+
* With no embedding variables configured this returns undefined and performs
|
|
67
|
+
* no network setup. A partial or invalid configuration throws instead of
|
|
68
|
+
* silently falling back to lexical search or another provider.
|
|
69
|
+
*/
|
|
70
|
+
export declare function createEmbeddingProviderFromEnv(env?: Record<string, string | undefined>): EmbeddingProvider | undefined;
|
|
71
|
+
/** Create the HTTP adapter. No request is made until embed() is called. */
|
|
72
|
+
export declare function createHttpEmbeddingProvider(config: HttpEmbeddingProviderConfig): EmbeddingProvider;
|