@mnmal-ai/cortext 0.0.0-stage → 1.0.0-alpha.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/LICENSE +202 -0
- package/README.md +71 -2
- package/config.schema.json +62 -0
- package/default-config.json +10 -0
- package/dist/auth-policy.d.ts +44 -0
- package/dist/bootstrap.d.ts +36 -0
- package/dist/bootstrap.js +69 -0
- package/dist/compact.d.ts +37 -0
- package/dist/config.d.ts +40 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +5 -0
- package/dist/kernel/bootstrap.d.ts +11 -0
- package/dist/kernel/cortext-namespace.d.ts +96 -0
- package/dist/kernel/index.d.ts +15 -0
- package/dist/kernel/invariant-audit.d.ts +190 -0
- package/dist/kernel/migrations/0001_baseline.d.ts +11 -0
- package/dist/kernel/plugin.d.ts +29 -0
- package/dist/kernel/repair.d.ts +94 -0
- package/dist/kernel/rescope.d.ts +87 -0
- package/dist/kernel/substrate-contract.d.ts +19 -0
- package/dist/kernel/todo-vocab.d.ts +17 -0
- package/dist/kernel-bootstrap.js +21 -0
- package/dist/kernel-invariants.d.ts +62 -0
- package/dist/kernel.js +3 -0
- package/dist/mailbox.d.ts +80 -0
- package/dist/namespace.d.ts +159 -0
- package/dist/nl-rulings.d.ts +76 -0
- package/dist/onboard.d.ts +15 -0
- package/dist/participants.d.ts +32 -0
- package/dist/plugin-27UpMnoE.js +811 -0
- package/dist/release-surface.d.ts +206 -0
- package/dist/src-BKaGTnRw.js +1931 -0
- package/dist/todo-resolution.d.ts +18 -0
- package/kernel.config.schema.json +8 -0
- package/kernel.default-config.json +1 -0
- package/package.json +80 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mnmal-ai/cortext
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Substrate plugins for the agent's persistent context store: a coordinator and its kernel-tier sibling, shipped as one package.
|
|
4
|
+
|
|
5
|
+
Owns the `cortext` namespace — `Todo`, `Decision`, `SessionLog`, `AgentRule`, `AnchorIntent`, `Concept`, `ConceptLink`, `Memory`, `CouncilSession`, `AgentIdentity`, `AgentMessage`, `Skill`. This is the data backbone that lets a session restart and pick up where it left off: cold-start hooks query this namespace to inject recent context; mutations during a session land here too. Compaction sweeps stale rows by per-type retention rules. Code-review findings that outlive a session live in a sibling `architecture` namespace this plugin also owns.
|
|
6
|
+
|
|
7
|
+
## Where it fits
|
|
8
|
+
|
|
9
|
+
Installed into a substrate deployment's `SUBSTRATE_PLUGIN_DIR` (manifest-driven loader). The manifest's `substrate.plugins` declares two entries, `kernel` and `coordinator`, and the loader brings up both. The only runtime peer is `@mnmal-ai/substrate`: the type DSL comes from `@mnmal-ai/substrate/sdk`, and semantic-recall hooks are contributed by substrate's recall plugin, which walks the `embed.source` metadata declared here.
|
|
10
|
+
|
|
11
|
+
## Kernel plugin
|
|
12
|
+
|
|
13
|
+
`src/kernel/` holds the kernel-tier plugin (runtime name `cortext-kernel`, exported as `createCortextKernelPlugin()` from `@mnmal-ai/cortext/kernel`). It owns the postgres-level invariants for the `cortext/*` and `architecture/*` namespaces that cannot live in the engine-side validator: vocabulary CHECK constraints, partial unique indexes and one-time body normalisations, as migrations `0001`-`0008` in `src/kernel/migrations/`. Migration order is load-bearing; see `src/kernel/plugin.ts`.
|
|
14
|
+
|
|
15
|
+
On every boot its `onKernelReady` handler audits those objects against the catalog and reports any that are missing, left NOT VALID, or scoped to a namespace no coordinator declares (`src/kernel/invariant-audit.ts`). Repair is opt-in via `SYNOPTIC_CORTEXT_REPAIR` (`src/kernel/repair.ts`). It takes no operator config (`kernel.default-config.json` is `{}`).
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install --prefix /opt/substrate/plugins @mnmal-ai/cortext
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Defaults (`namespace=cortext`, `architectureNamespace=architecture`, `compactRetention=7`) ship in `default-config.json`. To override, drop a `<SUBSTRATE_PLUGIN_DIR>/cortext.config.json`:
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"namespace": "cortext",
|
|
28
|
+
"architectureNamespace": "architecture",
|
|
29
|
+
"compactRetention": 14
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Auth posture
|
|
34
|
+
|
|
35
|
+
The context store is the agent's memory estate; what anonymous callers may do
|
|
36
|
+
with it is an operator knob, not a baked-in choice:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"auth": {
|
|
41
|
+
"reads": "open",
|
|
42
|
+
"writes": "identity",
|
|
43
|
+
"deletes": "identity"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Each surface is `"open"` (anonymous allowed) or `"identity"` (verified token
|
|
49
|
+
required). Defaults: `reads`/`writes` open, `deletes` identity-gated — a fresh
|
|
50
|
+
install works keyless end to end; only anonymous hard-deletes (incl. `purge`)
|
|
51
|
+
are refused, with `archived: true` as the open soft path. Strictness must be
|
|
52
|
+
monotonic along `reads → writes → deletes`; the config loader rejects
|
|
53
|
+
incoherent postures (e.g. gated reads over open writes) at boot.
|
|
54
|
+
|
|
55
|
+
The knob maps to plugin-level policy combinators at compose time
|
|
56
|
+
(`src/auth-policy.ts`) covering **both** namespaces. AutoCRUD type definitions
|
|
57
|
+
are untouched — tightening posture later is config-only, no schema or client
|
|
58
|
+
migration. Pair with attribute-mode auth so consumers can adopt signing keys
|
|
59
|
+
before any enforcement flips (key issuance and the retrofit path are
|
|
60
|
+
documented in the substrate repo, not here).
|
|
61
|
+
The plugin's scheduled compact task writes with a
|
|
62
|
+
`{kind:'system', id:'cortext:compact'}` envelope and keeps working under
|
|
63
|
+
gated writes.
|
|
64
|
+
|
|
65
|
+
Read-surface coverage: substrate's `/substrate/v1/recall` route and its
|
|
66
|
+
`recall` MCP tool honour these same policies via
|
|
67
|
+
`engine.evaluateReadPolicy` — semantic recall is not a
|
|
68
|
+
side-channel around `reads: "identity"`.
|
|
69
|
+
|
|
70
|
+
## More
|
|
71
|
+
|
|
72
|
+
- Type definitions: `src/namespace.ts`
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"namespace": {
|
|
6
|
+
"default": "cortext",
|
|
7
|
+
"type": "string",
|
|
8
|
+
"minLength": 1
|
|
9
|
+
},
|
|
10
|
+
"architectureNamespace": {
|
|
11
|
+
"default": "architecture",
|
|
12
|
+
"type": "string",
|
|
13
|
+
"minLength": 1
|
|
14
|
+
},
|
|
15
|
+
"compactRetention": {
|
|
16
|
+
"default": 7,
|
|
17
|
+
"type": "integer",
|
|
18
|
+
"exclusiveMinimum": 0,
|
|
19
|
+
"maximum": 9007199254740991
|
|
20
|
+
},
|
|
21
|
+
"autoCompactIntervalMs": {
|
|
22
|
+
"type": "number",
|
|
23
|
+
"exclusiveMinimum": 0
|
|
24
|
+
},
|
|
25
|
+
"auth": {
|
|
26
|
+
"default": {
|
|
27
|
+
"reads": "open",
|
|
28
|
+
"writes": "open",
|
|
29
|
+
"deletes": "identity"
|
|
30
|
+
},
|
|
31
|
+
"type": "object",
|
|
32
|
+
"properties": {
|
|
33
|
+
"reads": {
|
|
34
|
+
"default": "open",
|
|
35
|
+
"type": "string",
|
|
36
|
+
"enum": [
|
|
37
|
+
"open",
|
|
38
|
+
"identity"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"writes": {
|
|
42
|
+
"default": "open",
|
|
43
|
+
"type": "string",
|
|
44
|
+
"enum": [
|
|
45
|
+
"open",
|
|
46
|
+
"identity"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"deletes": {
|
|
50
|
+
"default": "identity",
|
|
51
|
+
"type": "string",
|
|
52
|
+
"enum": [
|
|
53
|
+
"open",
|
|
54
|
+
"identity"
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"additionalProperties": false
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"additionalProperties": false
|
|
62
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth-posture → policy mapping.
|
|
3
|
+
*
|
|
4
|
+
* The posture knob deliberately lives OUTSIDE the autoCRUD type definitions —
|
|
5
|
+
* it maps onto plugin-level policy combinators at compose time, which is what
|
|
6
|
+
* makes it retrofit-capable: a deployment can start fully open and tighten to
|
|
7
|
+
* identity-gated writes (or full lockdown) later by config alone. No schema
|
|
8
|
+
* migration, no client changes — consumers that already sign never notice the
|
|
9
|
+
* flip. The wire mechanism for this is attribute-mode auth: tokens are
|
|
10
|
+
* verified and attributed whenever present, so credential adoption can run
|
|
11
|
+
* ahead of enforcement.
|
|
12
|
+
*
|
|
13
|
+
* Monotonicity: strictness must be non-decreasing along reads → writes →
|
|
14
|
+
* deletes. "Anonymous may write but not read" has no coherent threat model;
|
|
15
|
+
* rejecting it keeps the mapping a simple ladder.
|
|
16
|
+
*
|
|
17
|
+
* Read-surface coverage: substrate's /substrate/v1/recall route and its
|
|
18
|
+
* recall MCP tool honour these same policies via
|
|
19
|
+
* `engine.evaluateReadPolicy` — recall is not a side-channel
|
|
20
|
+
* around `reads: 'identity'`. Any future embeddings-fetch route must inherit
|
|
21
|
+
* the same check.
|
|
22
|
+
*/
|
|
23
|
+
import type { Policy } from '@mnmal-ai/substrate/sdk';
|
|
24
|
+
import type { CortextAuthConfig } from './config.js';
|
|
25
|
+
/**
|
|
26
|
+
* The default: anonymous read/create/update under
|
|
27
|
+
* attribute mode, identity-gated hard-deletes. Archive stays the open soft path.
|
|
28
|
+
*/
|
|
29
|
+
export declare const DEFAULT_AUTH: CortextAuthConfig;
|
|
30
|
+
/** Strictness must be non-decreasing along reads → writes → deletes. */
|
|
31
|
+
export declare function isMonotonicAuth(auth: CortextAuthConfig): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Map a posture to the plugin-level policy list. Combinator order matters:
|
|
34
|
+
* `or()` returns the LAST deny verbatim, so the deny arm's actionable reason
|
|
35
|
+
* surfaces on denial instead of requireIdentity's terse default.
|
|
36
|
+
*
|
|
37
|
+
* Monotonicity makes the mapping a ladder — the strictest gated surface
|
|
38
|
+
* determines the single composed policy:
|
|
39
|
+
* reads gated → everything requires identity
|
|
40
|
+
* writes gated → create/update/delete require identity, reads stay open
|
|
41
|
+
* deletes gated → only the destructive verbs require identity
|
|
42
|
+
* fully open → no policy contributed at all
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildAuthPolicies(auth: CortextAuthConfig): Policy[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured-config bootstrap for `@mnmal-ai/cortext`.
|
|
3
|
+
*
|
|
4
|
+
* The canonical entry consumed by the binary's `SUBSTRATE_PLUGIN_DIR` loader.
|
|
5
|
+
*
|
|
6
|
+
* Operator JSON config supplies the env-shape knobs (namespace,
|
|
7
|
+
* architectureNamespace, compactRetention, autoCompactIntervalMs); the
|
|
8
|
+
* bootstrap parses + validates and hands off to `createCortextPlugin`.
|
|
9
|
+
* Embeddable types (Memory, SessionLog, Decision, AnchorIntent, Concept)
|
|
10
|
+
* declare `embed.source` metadata; substrate's recall plugin walks this at compose time
|
|
11
|
+
* and chains an embedding postWrite per match via `contributePostWrites`.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
export declare const CortextBootstrapConfigSchema: z.ZodObject<{
|
|
15
|
+
namespace: z.ZodDefault<z.ZodString>;
|
|
16
|
+
architectureNamespace: z.ZodDefault<z.ZodString>;
|
|
17
|
+
compactRetention: z.ZodDefault<z.ZodNumber>;
|
|
18
|
+
autoCompactIntervalMs: z.ZodOptional<z.ZodNumber>;
|
|
19
|
+
auth: z.ZodDefault<z.ZodObject<{
|
|
20
|
+
reads: z.ZodDefault<z.ZodEnum<{
|
|
21
|
+
identity: "identity";
|
|
22
|
+
open: "open";
|
|
23
|
+
}>>;
|
|
24
|
+
writes: z.ZodDefault<z.ZodEnum<{
|
|
25
|
+
identity: "identity";
|
|
26
|
+
open: "open";
|
|
27
|
+
}>>;
|
|
28
|
+
deletes: z.ZodDefault<z.ZodEnum<{
|
|
29
|
+
identity: "identity";
|
|
30
|
+
open: "open";
|
|
31
|
+
}>>;
|
|
32
|
+
}, z.core.$strict>>;
|
|
33
|
+
}, z.core.$strict>;
|
|
34
|
+
export type CortextBootstrapConfig = z.infer<typeof CortextBootstrapConfigSchema>;
|
|
35
|
+
export declare const bootstrap: import("@mnmal-ai/substrate/sdk").CoordinatorBootstrap;
|
|
36
|
+
export default bootstrap;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { E as isMonotonicAuth, t as createCortextPlugin, w as DEFAULT_AUTH } from "./src-BKaGTnRw.js";
|
|
2
|
+
import { D as ARCHITECTURE_NAMESPACE, k as CORTEXT_NAMESPACE } from "./plugin-27UpMnoE.js";
|
|
3
|
+
import "./kernel.js";
|
|
4
|
+
import { defineBootstrap } from "@mnmal-ai/substrate/sdk";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
//#region src/bootstrap.ts
|
|
8
|
+
/**
|
|
9
|
+
* Structured-config bootstrap for `@mnmal-ai/cortext`.
|
|
10
|
+
*
|
|
11
|
+
* The canonical entry consumed by the binary's `SUBSTRATE_PLUGIN_DIR` loader.
|
|
12
|
+
*
|
|
13
|
+
* Operator JSON config supplies the env-shape knobs (namespace,
|
|
14
|
+
* architectureNamespace, compactRetention, autoCompactIntervalMs); the
|
|
15
|
+
* bootstrap parses + validates and hands off to `createCortextPlugin`.
|
|
16
|
+
* Embeddable types (Memory, SessionLog, Decision, AnchorIntent, Concept)
|
|
17
|
+
* declare `embed.source` metadata; substrate's recall plugin walks this at compose time
|
|
18
|
+
* and chains an embedding postWrite per match via `contributePostWrites`.
|
|
19
|
+
*/
|
|
20
|
+
const NamespaceSchema = z.string().min(1, "must not be empty").refine((s) => !s.includes("/"), { message: "must not contain '/'" });
|
|
21
|
+
/**
|
|
22
|
+
* Namespace overrides stay SUPPORTED. The kernel cannot follow a renamed
|
|
23
|
+
* namespace, so using one silently disables every kernel invariant — that
|
|
24
|
+
* is reported at boot by `reportUncoveredNamespaces` (./kernel-invariants.ts),
|
|
25
|
+
* wired into the plugin's `onStart`.
|
|
26
|
+
*
|
|
27
|
+
* They are not pinned to the kernel's literals: per-cohort context stores are a
|
|
28
|
+
* designed capability with a test that names `codex` explicitly. The knob
|
|
29
|
+
* stays; only the silence goes.
|
|
30
|
+
*/
|
|
31
|
+
const AuthModeSchema = z.enum(["open", "identity"]);
|
|
32
|
+
/**
|
|
33
|
+
* Auth posture knob. Defaults: reads/writes open, hard-deletes
|
|
34
|
+
* identity-gated. Operators
|
|
35
|
+
* tighten (or fully open) per deployment — see ./auth-policy.ts for the
|
|
36
|
+
* posture → policy mapping and the monotonicity invariant.
|
|
37
|
+
*/
|
|
38
|
+
const AuthPostureSchema = z.object({
|
|
39
|
+
reads: AuthModeSchema.default(DEFAULT_AUTH.reads),
|
|
40
|
+
writes: AuthModeSchema.default(DEFAULT_AUTH.writes),
|
|
41
|
+
deletes: AuthModeSchema.default(DEFAULT_AUTH.deletes)
|
|
42
|
+
}).strict();
|
|
43
|
+
const CortextBootstrapConfigSchema = z.object({
|
|
44
|
+
namespace: NamespaceSchema.default(CORTEXT_NAMESPACE),
|
|
45
|
+
architectureNamespace: NamespaceSchema.default(ARCHITECTURE_NAMESPACE),
|
|
46
|
+
compactRetention: z.number().int().positive().default(7),
|
|
47
|
+
/** Auto-compact tick interval in milliseconds. Omitted = disabled. */
|
|
48
|
+
autoCompactIntervalMs: z.number().positive().optional(),
|
|
49
|
+
auth: AuthPostureSchema.default({ ...DEFAULT_AUTH })
|
|
50
|
+
}).strict().refine((cfg) => cfg.namespace !== cfg.architectureNamespace, {
|
|
51
|
+
message: "architectureNamespace must differ from namespace",
|
|
52
|
+
path: ["architectureNamespace"]
|
|
53
|
+
}).refine((cfg) => isMonotonicAuth(cfg.auth), {
|
|
54
|
+
message: "auth posture must be monotonic — strictness non-decreasing along reads → writes → deletes (e.g. writes:'identity' requires deletes:'identity')",
|
|
55
|
+
path: ["auth"]
|
|
56
|
+
});
|
|
57
|
+
const bootstrap = defineBootstrap.coordinator({
|
|
58
|
+
schema: CortextBootstrapConfigSchema,
|
|
59
|
+
build: (config) => createCortextPlugin({
|
|
60
|
+
namespace: config.namespace,
|
|
61
|
+
architectureNamespace: config.architectureNamespace,
|
|
62
|
+
compactRetention: config.compactRetention,
|
|
63
|
+
autoCompactIntervalMs: config.autoCompactIntervalMs,
|
|
64
|
+
auth: config.auth
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { CortextBootstrapConfigSchema, bootstrap, bootstrap as default };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compact route — archives old sessions and cascades the archive flag onto
|
|
3
|
+
* their decisions:
|
|
4
|
+
* 1. Read live SessionLog rows newest first; keep the newest `retention`
|
|
5
|
+
* PER PROJECT (a global window lets a busy project empty a quiet one).
|
|
6
|
+
* 2. Cascade-archive every live Decision whose `sessionId` points at a
|
|
7
|
+
* session being archived, or that another Decision's `supersedes`
|
|
8
|
+
* names (not the Decision CARRYING `supersedes`, which is the current one).
|
|
9
|
+
* 3. Archive the decisions, then the sessions, so a failure between the
|
|
10
|
+
* two writes is recomputed by the next run instead of lost.
|
|
11
|
+
*
|
|
12
|
+
* `EngineHandle` is namespace-agnostic — the caller
|
|
13
|
+
* supplies qualified keys (§4.7) — so we wrap the engine locally with two
|
|
14
|
+
* tiny adapters: `queryAll` (envelope → typed rows) and `mutateOne` (run one
|
|
15
|
+
* mutation by name). Both thread through a `RequestContext` that mirrors what
|
|
16
|
+
* the HTTP route layer constructs.
|
|
17
|
+
*/
|
|
18
|
+
import type { EngineHandle, PluginRouteContext, PluginRouter } from '@mnmal-ai/substrate/sdk';
|
|
19
|
+
import type { CortextAuthConfig } from './config.js';
|
|
20
|
+
export interface CompactResult {
|
|
21
|
+
dryRun: boolean;
|
|
22
|
+
sessionsArchived: number;
|
|
23
|
+
decisionsArchived: number;
|
|
24
|
+
sessionsRetained: number;
|
|
25
|
+
messagesArchived: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Tunables for the per-call compact behaviour beyond the session-retention
|
|
29
|
+
* count. `mailMaxAgeMs` exists primarily for tests — `_metadata` timestamps
|
|
30
|
+
* are server-stamped, so a test can't author old mail; it shrinks the window
|
|
31
|
+
* instead.
|
|
32
|
+
*/
|
|
33
|
+
export interface CompactOptions {
|
|
34
|
+
mailMaxAgeMs?: number;
|
|
35
|
+
}
|
|
36
|
+
export declare function runCompact(engine: EngineHandle, ns: string, retention: number, dryRun: boolean, opts?: CompactOptions): Promise<CompactResult>;
|
|
37
|
+
export declare function registerCompactRoute(router: PluginRouter, ctx: PluginRouteContext, retention: number, namespace: string, auth?: CortextAuthConfig): void;
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cortext plugin config type.
|
|
3
|
+
*
|
|
4
|
+
* Pure type definition — config is supplied to `createCortextPlugin` either
|
|
5
|
+
* by the structured-config bootstrap (operator JSON config + optional
|
|
6
|
+
* code-shaped extras) or by direct programmatic callers (tests). Validation
|
|
7
|
+
* and defaults live in the bootstrap layer (zod schema in `bootstrap.ts`).
|
|
8
|
+
*/
|
|
9
|
+
/** Per-surface auth posture: anonymous allowed, or authenticated identity required. */
|
|
10
|
+
export type CortextAuthMode = 'open' | 'identity';
|
|
11
|
+
/**
|
|
12
|
+
* Auth posture knob ("open initially, retrofit-capable").
|
|
13
|
+
* Maps onto plugin-level policy combinators at compose time; autoCRUD type
|
|
14
|
+
* definitions are untouched, so any deployment can tighten posture later by
|
|
15
|
+
* config alone. Strictness must be monotonic: reads ≤ writes ≤ deletes.
|
|
16
|
+
*/
|
|
17
|
+
export interface CortextAuthConfig {
|
|
18
|
+
/** Type queries + get<T> (and subscribe/stream dispatch). */
|
|
19
|
+
reads: CortextAuthMode;
|
|
20
|
+
/** create<T> + update<T>. */
|
|
21
|
+
writes: CortextAuthMode;
|
|
22
|
+
/** delete<T>, incl. purge<T> via its verb:'delete' stamp. */
|
|
23
|
+
deletes: CortextAuthMode;
|
|
24
|
+
}
|
|
25
|
+
export interface CortextPluginConfig {
|
|
26
|
+
/** Namespace the context-store types register under. */
|
|
27
|
+
namespace: string;
|
|
28
|
+
/**
|
|
29
|
+
* Namespace the architecture-findings type (`ArchitectureConcern`) registers
|
|
30
|
+
* under. Kept separate from the context store so compaction / retention /
|
|
31
|
+
* audit policies diverge.
|
|
32
|
+
*/
|
|
33
|
+
architectureNamespace: string;
|
|
34
|
+
/** Number of recent sessions to keep live during compaction. */
|
|
35
|
+
compactRetention: number;
|
|
36
|
+
/** Auto-compact interval in milliseconds. Undefined = disabled. */
|
|
37
|
+
autoCompactIntervalMs: number | undefined;
|
|
38
|
+
/** Auth posture. Undefined = DEFAULT_AUTH (reads/writes open, deletes identity). */
|
|
39
|
+
auth: CortextAuthConfig | undefined;
|
|
40
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mnmal-ai/cortext — coordinator plugin that persists Claude Code
|
|
3
|
+
* context (sessions, decisions, todos, rules, reviews, councils, skills) plus
|
|
4
|
+
* Claude-lineage architecture findings.
|
|
5
|
+
*
|
|
6
|
+
* Binds the context store onto the coordinator plugin seam (§5.11):
|
|
7
|
+
* - `namespaces[0]` — the 13-type context-store surface (see `./namespace.ts`).
|
|
8
|
+
* - `namespaces[1]` — the `architecture` surface (`ArchitectureConcern`),
|
|
9
|
+
* kept in a distinct namespace so lifecycle policies (compaction,
|
|
10
|
+
* retention, audit) diverge from session-scoped rationale.
|
|
11
|
+
* - `routes` — `/onboard` (static agent self-description) and `/compact`
|
|
12
|
+
* (session archiver — operates on the claude namespace only).
|
|
13
|
+
* - `schedule` — an auto-compact task when `autoCompactIntervalMs` is set
|
|
14
|
+
* in the operator's `cortext.config.json`; otherwise the plugin
|
|
15
|
+
* ships with no scheduled tasks and relies on explicit
|
|
16
|
+
* `POST /substrate/v1/plugins/cortext/compact` calls.
|
|
17
|
+
*
|
|
18
|
+
* `createCortextPlugin` is a pure factory taking a fully-resolved
|
|
19
|
+
* `CortextPluginConfig`. Recall/embedding wiring is entirely declarative:
|
|
20
|
+
* embeddable types declare `embed.source` slots on their namespace definitions,
|
|
21
|
+
* and kernel plugins (e.g. substrate's recall plugin) walk that metadata at compose
|
|
22
|
+
* time to contribute postWrite hooks via the engine's kernel-walk.
|
|
23
|
+
*/
|
|
24
|
+
import type { CoordinatorPlugin } from '@mnmal-ai/substrate/sdk';
|
|
25
|
+
import type { CortextPluginConfig } from './config.js';
|
|
26
|
+
export { buildAuthPolicies, DEFAULT_AUTH, isMonotonicAuth } from './auth-policy.js';
|
|
27
|
+
export { type CompactResult, registerCompactRoute, runCompact } from './compact.js';
|
|
28
|
+
export type { CortextAuthConfig, CortextAuthMode, CortextPluginConfig } from './config.js';
|
|
29
|
+
export { AGENT_MESSAGE_STATUS_VOCAB, AGENT_RULE_CATEGORY_VOCAB, AGENT_RULE_SEVERITY_ALIASES, AGENT_RULE_SEVERITY_VOCAB, ARCHITECTURE_TYPE_NAMES, buildArchitectureNamespace, buildClaudeNamespace, CLAUDE_TYPE_NAMES, DECISION_STATUS_ALIASES, DECISION_STATUS_VOCAB, HOST_INSTALL_CHECK_STATES, HOST_INSTALL_FRAGMENT_STATES, TODO_RESOLUTION_ALIASES, TODO_STATUS_ALIASES, TODO_STATUS_IMPLIES } from './namespace.js';
|
|
30
|
+
export { registerOnboardRoute } from './onboard.js';
|
|
31
|
+
export { buildReleaseSurface, bumpClass, classifySurfaceChange, classSatisfies, type ReleaseClass, type ReleaseSurface, type SurfaceChange, type SurfaceField } from './release-surface.js';
|
|
32
|
+
export { type ClosedTodoText, inferTodoResolution, type TodoResolution } from './todo-resolution.js';
|
|
33
|
+
export declare function createCortextPlugin(cfg: CortextPluginConfig): CoordinatorPlugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { C as runCompact, E as isMonotonicAuth, S as registerCompactRoute, T as buildAuthPolicies, _ as TODO_RESOLUTION_ALIASES, a as classSatisfies, b as buildArchitectureNamespace, c as AGENT_RULE_CATEGORY_VOCAB, d as ARCHITECTURE_TYPE_NAMES, f as CLAUDE_TYPE_NAMES, g as HOST_INSTALL_FRAGMENT_STATES, h as HOST_INSTALL_CHECK_STATES, i as bumpClass, l as AGENT_RULE_SEVERITY_ALIASES, m as DECISION_STATUS_VOCAB, n as inferTodoResolution, o as classifySurfaceChange, p as DECISION_STATUS_ALIASES, r as buildReleaseSurface, s as registerOnboardRoute, t as createCortextPlugin, u as AGENT_RULE_SEVERITY_VOCAB, v as TODO_STATUS_ALIASES, w as DEFAULT_AUTH, x as buildClaudeNamespace, y as TODO_STATUS_IMPLIES } from "./src-BKaGTnRw.js";
|
|
2
|
+
import { g as AGENT_MESSAGE_STATUS_VOCAB } from "./plugin-27UpMnoE.js";
|
|
3
|
+
import "./kernel.js";
|
|
4
|
+
|
|
5
|
+
export { AGENT_MESSAGE_STATUS_VOCAB, AGENT_RULE_CATEGORY_VOCAB, AGENT_RULE_SEVERITY_ALIASES, AGENT_RULE_SEVERITY_VOCAB, ARCHITECTURE_TYPE_NAMES, CLAUDE_TYPE_NAMES, DECISION_STATUS_ALIASES, DECISION_STATUS_VOCAB, DEFAULT_AUTH, HOST_INSTALL_CHECK_STATES, HOST_INSTALL_FRAGMENT_STATES, TODO_RESOLUTION_ALIASES, TODO_STATUS_ALIASES, TODO_STATUS_IMPLIES, buildArchitectureNamespace, buildAuthPolicies, buildClaudeNamespace, buildReleaseSurface, bumpClass, classSatisfies, classifySurfaceChange, createCortextPlugin, inferTodoResolution, isMonotonicAuth, registerCompactRoute, registerOnboardRoute, runCompact };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured-config bootstrap for cortext's kernel plugin
|
|
3
|
+
* (mirrors the recall + plane bootstrap pattern).
|
|
4
|
+
*
|
|
5
|
+
* No operator-overridable surface today — the plugin contributes a
|
|
6
|
+
* static migration list and nothing else. Reserved for future schema-
|
|
7
|
+
* level controls if any emerge.
|
|
8
|
+
*/
|
|
9
|
+
type CortextKernelHostDeps = Record<string, never>;
|
|
10
|
+
export declare const bootstrap: import("@mnmal-ai/substrate/sdk").KernelBootstrap<CortextKernelHostDeps>;
|
|
11
|
+
export default bootstrap;
|